Webpack 4-Autoprefixer不会在package.json中的浏览器列表中添加开发中的前缀

时间:2018-08-18 13:12:06

标签: webpack environment-variables webpack-4 autoprefixer

当我运行脚本dev或prod时,自动前缀会在browserlist-production中从浏览器添加前缀。如何设置环境变量NODE_ENV或BROWSERLIST_ENV?我想在运行“ yarn run dev”时从browserslist-development中添加前缀。

在package.json中

  "scripts": {
    "dev": "webpack --mode development",
    "prod": "webpack --mode production"
  },

"browserslist": {
    "production": [
      "ie >= 8"
    ],
    "development": [
      "last 1 chrome version"
    ]
  }

webpack.config.js

var path = require('path');

const ExtractCssChunks = require("extract-css-chunks-webpack-plugin");

const webpack = require("webpack");

module.exports = {
    entry: './src/scripts/main.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },
    devtool: 'source-map',
    module: {
        rules: [
            {
                test: /\.css$/,
                exclude: /node_modules/,
                use:
                    [
                        ExtractCssChunks.loader,
                        {
                            loader: 'css-loader',
                            options: {
                                sourceMap: true,
                            }
                        },
                        {
                            loader: 'postcss-loader',
                            options: {
                                plugins: function() {
                                    return [
                                        require('postcss-import')(),
                                        require('autoprefixer')()
                                    ]
                                }
                            }
                        }
                    ]

            }
        ]
    },

    plugins: [
        new ExtractCssChunks({
            filename: "bundle.css",
        })
    ]
}

0 个答案:

没有答案