How do I turn off source maps in production in Gatsby v2?

*爱你&永不变心* 提交于 2021-02-08 15:18:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!