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. 微信 登录 Scope 参数错误或没有 Scope 权限

    //电脑端 扫码授权登录 public static string AuthUrl = "https://open.weixin.qq.com/connect/qrconnect?appid ...

  2. jacascript 原生选项卡插件

    前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! 在布局的时候,想到了很多以前看到过的案例,再次熟悉一下: a链接之间的竖线:可以用a链接的border-r ...

  3. 你真的会websocket吗

    Websocket WebSocket协议是基于TCP的一种新的网络协议.它实现了浏览器与服务器全双工(full-duplex)通信——允许服务器主动发送信息给客户端. WebSocket通信协议于2 ...

  4. MSIL实用指南-闭包的生成和调用

    闭包(Closure)是词法闭包(Lexical Closure)的简称.对闭包的具体定义有很多种说法,这些说法大体可以分为两类: 一种说法认为闭包是符合一定条件的函数,比如参考资源中这样定义闭包:闭 ...

  5. java中的链表编写

    通过while循环取出节点内容 class Node{//定义一个节点类,用于保存数据和取得下一个节点 private String data;//节点中数据 private Node next;// ...

  6. [LeetCode] Array Nesting 数组嵌套

    A zero-indexed array A consisting of N different integers is given. The array contains all integers ...

  7. [LeetCode] Accounts Merge 账户合并

    Given a list accounts, each element accounts[i] is a list of strings, where the first element accoun ...

  8. hadoop一键安装伪分布式

    hadoop伪分布式和hive在openSUSE中的安装 在git上的路径为:https://github.com/huabingood/hadoop--------/tree/master 各个文件 ...

  9. 极客验证官方demo构建使用及代码分析

    #什么是极客验证? 官方定义:极验验证是一种在计算机领域用于区分自然人和机器人的,通过简单集成的方式,为开发者提供安全.便捷的云端验证服务. #使用命令从github上获取: git clone ht ...

  10. ●BZOJ 1416 [NOI2006]神奇的口袋

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1416题解: Pòlya瓦罐模型: 给定罐子里每种颜色的球的个数A[i],按题目要求随机操作若 ...