简体   繁体   中英

webpack4 how to config postcss.config.js file in production mode

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack-dev-server  --mode development --open --progress --config webpack.dev.config.js",
    "build": "webpack --progress --mode production --config webpack.prod.config.js"
  },



  module.exports = ({env}) => ({
  plugins: {
    'cssnano': env === 'production' ? {} : false
  }
});

when I run "npm run build", the env is always "development",so the "cssnano" doesn't run. How to let the postcss knows that I'm in the "production"?

Try

module.exports = (env, argv) => ({
…
plugins: {
    'cssnano': argv.mode === 'production' ? {} : false
}
…

这有帮助吗?

"build": "NODE_ENV=production webpack --progress --mode production --config webpack.prod.config.js"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM