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$/
}))
}

webpack 命令行 传入自定义变量的更多相关文章

  1. webpack命令行

    前面的话 webpack提供了命令行接口(CLI),以便对构建过程进行配置和交互.这对于制定早期原型.轮廓.编写 npm 脚本 或者一些个人自定义需求很有用.本文将详细介绍webpack的命令行接口 ...

  2. spring boot 项目打包后无法通过命令行传入参数

    java -jar .\tk-provider.jar --spring.profiles.active=test 本想用测试环境的配置文件运行项目可项目启动时一直是使用dev配置文件运行. java ...

  3. webpack 命令行报错“webpack” 不是内部或外部命令的解决方法

    1. NodeJS安装,笔者安装在D盘.安装目录中有两个文件夹node_cache,node_global如下: 2. 配置 npm安装路径,输入如下命令: npm config set prefix ...

  4. nodejs 命令行、自定义

    一.必备插件 1. babel:es6语法支持,需要babel-perset-es2015(转换成es5执行).babel.babel-core(程序执行) 2. commander:自定义命令插件, ...

  5. apollo命令行传入参数

    Java apollo客户端运行配置 需要在META-INF中创建app.properties文件,以配置app.id 还需要在/opt/settings/server.properties或C:/o ...

  6. Linux命令行设置环境变量

    参考  Linux命令行--使用linux环境变量  Linux命令行—使用Linux环境变量

  7. hive 命令行传入参数

    azkban实现任务重跑 我们执行sql的方式是将hql文件上传到服务器本地.然后执行shell命令 hive " -f ./test_scheduler.hql 注:hive -e 是执行 ...

  8. Mac 命令行,自定义命令

    例如自定义命令 gotoXFolder, 直接进入XFolder文件夹, XFolder地址为~/abc/def/Xfolder 步骤: 1. 在home文件夹下创建.profile文件 在.prof ...

  9. cmd命令行设置环境变量

    http://blog.sciencenet.cn/blog-51026-566742.html 1.查看当前所有可用的环境变量:输入 set 即可查看. 2.查看某个环境变量:输入 “set 变量名 ...

随机推荐

  1. hdu1052 Tian Ji -- The Horse Racing---田忌赛马贪心

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1052 题目大意: 田忌和齐王各有N匹马,判断怎样比赛,使田忌净胜场数最多. 思路: 一开始贪心出错, ...

  2. win10 apache配置虚拟主机后localhost无法使用

    win10系统配置虚拟主机1.用记事本或Sublime Text打开httpd.confctrl + f 搜索httpd-vhosts.conf 将#Include conf/extra/httpd- ...

  3. h5视频和音频 -2018/04/16

    HTML5 规定了一种通过 video 元素来包含视频的标准方法. 当前video元素支持的三种视频格式: (1)Ogg 带有Theora视频编码和Vorbis音频编码的ogg文件 (2)MPEG4带 ...

  4. C#之PixturBox控件实现缩放和拖动图片

    一.实现鼠标滚轮控制图片缩放: 1.设置PixtureBox属性: Dock:none SizeMode:StretchImage 2.添加事件: pbxDrawing.MouseWheel += n ...

  5. [LeetCode] Super Washing Machines 超级洗衣机

    You have n super washing machines on a line. Initially, each washing machine has some dresses or is ...

  6. [LeetCode] Longest Word in Dictionary through Deleting 删除后得到的字典中的最长单词

    Given a string and a string dictionary, find the longest string in the dictionary that can be formed ...

  7. 【BZOJ3991】【SDOI2015】寻宝游戏

    Description ​ 小B最近正在玩一个寻宝游戏,这个游戏的地图中有N个村庄和N-1条道路,并且任何两个村庄之间有且仅有一条路径可达.游戏开始时,玩家可以任意选择一个村庄,瞬间转移到这个村庄,然 ...

  8. 【HNOI2002】【矩阵快速幂】公交车路线

    仍然是学弟出的题目的原题@lher 学弟将题目改成了多组数据,n在ll范围内,所以我就只讲提高版的做法. 链接:https://www.luogu.org/problem/show?pid=2233 ...

  9. [SPOJ705]不同的子串

    题目描述] 给定一个字符串,计算其不同的子串个数. [输入格式] 一行一个仅包含大写字母的字符串,长度<=50000 [输出格式] 一行一个正整数,即不同的子串个数. [样例输入] ABABA ...

  10. hdu 3433 A Task Process 二分+dp

    A Task Process Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...