问题
I'm struggling how to disable source maps for production since the default Webpack set up is to leave out the devtool option, but Gatsby v2 is enabling it. I've tried coming up with a way based on the old version and the new docs, but it doesn't work:
// gatsby-node.js
exports.onCreateWebpackConfig = ({ actions, stage }) => {
if (stage === 'build-javascript') {
// turn off source-maps
actions.setWebpackConfig({
devtool: false
})
}
};
回答1:
The code in the question is the correct solution. The problem was that Gatsby does not delete the /public/
folder on each build so previously created source maps were still there. So, first delete that folder, then run the build step.
回答2:
The above solution works. There is another option using gatsby plugin gatsby-plugin-no-sourcemaps
Install the plugin first
npm i gatsby-plugin-no-sourcemaps
After that goto gatsby-config.js
in your project root.
Add this in plugins array
gatsby-plugin-no-sourcemaps
Goto to public folder, delete all file. Run build command again gatsby build
. Now build will not have .map files.
gatsby-config.js
will look like this.
来源:https://stackoverflow.com/questions/51953898/how-do-i-turn-off-source-maps-in-production-in-gatsby-v2