Razzle: Disable SourceMaps in production

Created on 24 Apr 2019  路  5Comments  路  Source: jaredpalmer/razzle

Is there any way to disable generating of SourceMaps for production build?

CRA has .env variable called - GENERATE_SOURCEMAP.

I cannot see anything in docs. So, I suppose, the only possible way is to extend webpack config inside razzle.config.js?

Most helpful comment

@krazyjakee
This only seems to disable source maps for .js files.
.css files still get source map files generated.

All 5 comments

extend webpack config inside razzle.config.js

This is the solution. An example razzle.config.js.

module.exports = {
  modify: (config, { target, dev }) => {
    config.devtool = dev ? 'source-map' : false;
    return config;
  },
};

@krazyjakee yes that what I was talking about and I have the same in my code right now.
But this is a bit overcomplicated as for me to achieve such a goal. Not too accurate, to be honest.
Prefer the CRA way to do it.
However, if it is the only possible way then ok.

@Ronny25 If you really want to use environment variables you could do something like:

module.exports = {
  modify: config => {
    config.devtool = process.env.GENERATE_SOURCEMAP ? 'source-map' : false;
    return config;
  },
};

Then you get the same accuracy as CRA.

@krazyjakee that's not completely true 馃槃
Firstly, you need to create a config file with some logic inside then an env variable, sounds strange 馃槈
But I can live with is 馃榿

@krazyjakee
This only seems to disable source maps for .js files.
.css files still get source map files generated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jayphen picture Jayphen  路  4Comments

panbanda picture panbanda  路  5Comments

MaxGoh picture MaxGoh  路  4Comments

ewolfe picture ewolfe  路  4Comments

pseudo-su picture pseudo-su  路  3Comments