退房node-config
- 創建
default.js
其中包含你的開發的WebPack配置。
- 在
default.js
創建額外配置一個production.js
默認node-config
會選擇default.js
並將其提供給的WebPack。
如果您設置NODE_ENV=production
,它會選擇production.js
並執行Object.assign({}, default, production)
並將其提供給webpack。
通過這種方式,您將能夠管理n個env
config for webpack。
它幫助!
[更新]
添加一個例子來說明你的情況......
在項目的根目錄下創建config/default.js
export default {
entry: ['./foo/bar', './foo1/bar1'],
output: {
path: path.resolve('./build/js'),
filename: '[name].js',
publicPath: '/js/'
},
}
在根目錄下創建config/production.js
您的項目
export default {
entry: ['./foo/bar', './foo1/bar1', './new/entry'], //adding the new entry
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
}),
],
}
在項目的根目錄下創建webpack.config.babel.js
import config from 'config' //I'm using ES6 style. You can use require also
export default config.default //export the config based on the NODE_ENV
展會時間
webpack --progress --colors
default.js as the config
在這種情況下節點配置將返回
NODE_ENV=production
webpack --progress --colors
在這種情況下,node-config將同時採用default.js
和production.js
,並覆蓋超過default.js
(這裏來自production.js的條目和插件將在default.js中被覆蓋),並且它將返回帶有{entries(從production.js
),輸出(從default.js
),插件(從production.js
)},這是一個Object.assign()操作。
返回到default.js
。您需要重置NODE_ENV
NODE_ENV=
Yov可能需要使用export
或exports
,同時根據您的操作系統 希望它可以幫助做NODE_ENV
你能告訴我一個工作的例子嗎?我應該如何處理Object.assign? – asiniy
@asiniy你不需要對Object.assign()做任何事情。 node-config會照顧到這一點。我會添加一些例子。 –
'inject'是什麼意思?根據'env'添加額外的'entries'? –