简体   繁体   English

webpack4如何在生产模式下配置postcss.config.js文件

[英]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. 当我运行“ npm run build”时,env始终是“ development”,因此“ cssnano”不会运行。 How to let the postcss knows that I'm in the "production"? 如何让postcss知道我正在“制作”中?

Try 尝试

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

这有帮助吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 postcss.config.js 中为不同的 Webpack 入口点配置不同的 customProperties? - How can I configure different customProperties in postcss.config.js for different Webpack entry points? Webpack 2-导入会在postcss.config.js和其他js文件上引发错误 - Webpack 2 - import throws error on postcss.config.js and other js files 如何将postcss.config.js 和tailwind.config.js 转成ES 模块? - How to convert postcss.config.js and tailwind.config.js to ES modules? X [错误] [plugin esbuild-style-plugin] E:\...\postcss.config.js 的 PostCSS 配置文件无法加载 - X [ERROR] [plugin esbuild-style-plugin] PostCSS config file at E:\...\postcss.config.js can't load 如何在 Next js 自定义 postCSS 配置中配置 Scss 和 purgeCss - How to config Scss and purgeCss in Next js custom postCSS config 在Webpack生产配置中找不到Bundle.js - Bundle.js not found on webpack production config Webpack生产模式不会缩小js文件 - Webpack production mode does not minify js file 如果没有 webpack.config.js 文件,如何正确安装 Vuetify? - How to install Vuetify correctly if there is no webpack.config.js file? 如何在 webpack.config.js 文件中包含节点模块 - How to include node module in webpack.config.js file 如何从 webpack.config.js 文件访问环境变量? - How to access env vars from webpack.config.js file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM