sapper-template
sapper-template copied to clipboard
Don't tie `mode` to `NODE_ENV` in Webpack config
Was getting the following bug when NODE_ENV was set to staging:
$ sapper build
> Building...
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.mode should be one of these:
"development" | "production" | "none"
In other words, mode is not vis-a-vis the same as NODE_ENV in Webpack land. So this won't fly:
const mode = process.env.NODE_ENV;
Gosh. 🙃
We could in theory do something like the following:
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
But that's pretty limiting. CLI option? ENV var? https://webpack.js.org/concepts/mode/ mentions passing as config:
webpack --mode=production
Alternatively,
"scripts": {
"dev": "sapper dev",
"build": "NODE_ENV=production sapper build",
"export": "NODE_ENV=production sapper export",
}