zoukankan      html  css  js  c++  java
  • webpack 命令行 传入自定义变量

    https://github.com/webpack/webpack/issues/2254

    --env 变量

    Yes this is intended. Custom argumens can be passed via --env prefix, i. e. --env.compress. Than export a function from the webpack.config.js and it's called with the env parameter.

    module.exports = function(env) {
      // ...
      if (env.compress === 'true') {
        var CompressionPlugin = require('compression-webpack-plugin');
        config.plugins.push(
            new CompressionPlugin({
                asset: '{file}',
                algorithm: 'gzip',
                regExp: /.js$|.html$/
            }))
      }
    }
    
    

    通过 argv 访问

    In Webpack 1.x, I can pass in my own command line arguments like this:

    webpack --config ./webpack.config.prod.js --compress true

    Here --compress is the custom command line arguments, it can be used like this in the webpack.config.js:

    var argv = require('yargs').argv;
    
    if (argv.compress === 'true') {
        var CompressionPlugin = require('compression-webpack-plugin');
        config.plugins.push(
            new CompressionPlugin({
                asset: '{file}',
                algorithm: 'gzip',
                regExp: /.js$|.html$/
            }))
    }
    
  • 相关阅读:
    8086标志
    微内核
    枚举算法
    ajax
    面向对象技术概述
    ajax
    存储技术
    自然数组排列
    将搜索二叉树转换成双向链表
    在单链表中删除指定值的节点
  • 原文地址:https://www.cnblogs.com/xiangnan/p/5943148.html
Copyright © 2011-2022 走看看