Skip to content
This repository has been archived by the owner on Dec 12, 2017. It is now read-only.

Commit

Permalink
cooking: add env option
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Sep 26, 2016
1 parent 6982824 commit 73418e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
## 未发布
- cooking:
- watch 时增加 NamedModulesPlugin
- 新增 `env` 选项,设置 definePlugin。不填时会自动设置 process.env.NODE_ENV,如果传入字符串会覆盖原来的 NODE_ENV,传入对象会和原来的配置合并

## [v1.1.1] 2016.09.20
- cooking:
Expand Down
1 change: 1 addition & 0 deletions packages/cooking/util/is.js
Expand Up @@ -11,3 +11,4 @@ exports.Array = obj => type(obj) === '[object Array]'
exports.Object = obj => type(obj) === '[object Object]'
exports.Boolean = obj => type(obj) === '[object Boolean]'
exports.Function = obj => type(obj) === '[object Function]'
exports.nil = obj => obj === null || obj === undefined
22 changes: 15 additions & 7 deletions packages/cooking/util/merge.js
Expand Up @@ -84,6 +84,21 @@ module.exports = function (userConfig, baseConfig) {
config.output.umdNamedDefine = true
}

// node_env
if (is.Object(userConfig.env)) {
config.plugins.Define = new webpack.DefinePlugin(Object.assign({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}, userConfig.env))
} else {
config.plugins.Define = new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(
is.nil(userConfig.env) ?
process.env.NODE_ENV :
userConfig.env
)
})
}

// development
if (process.env.NODE_ENV === 'development') {
config.devtool = '#eval-source-map'
Expand Down Expand Up @@ -120,13 +135,6 @@ module.exports = function (userConfig, baseConfig) {
config.output.chunkFilename = '[id].[chunkhash:7].js'
}

// plugin
config.plugins.Define = new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
})

const minimize = userConfig.minimize
const UglifyJs = new webpack.optimize.UglifyJsPlugin({
compress: {warnings: false},
Expand Down

0 comments on commit 73418e0

Please sign in to comment.