0
我有一个用的WebPack与webpack.config.js文件反应项目这样如何使用webpack.config.js自定义配置?
const webpack = require('webpack');
const config = {
serverBaseUrl: 'http://localhost:3000',
devtool: "inline-source-map",
entry: __dirname + "/app/App.js",
output: {
path: "./public/js/",
publicPath: "/js/",
filename: "bundle.js"
},
module: {
loaders: [{
test: /.jsx?$/,
exclude: /node_modules/,
loader: "babel",
query: {
presets: ["es2015","react","stage-0"]
}
}]
},
devServer: {
port: 8008,
contentBase: "./public",
colors: true,
historyApiFallback: true,
inline: true
},
}
if (process.env.NODE_ENV === 'production') {
config.serverBaseUrl = 'http://api.domain.com';
config.devtool = false;
config.plugins = [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({comments: false}),
new webpack.DefinePlugin({
'process.env': {NODE_ENV: JSON.stringify('production')}
})
];
};
module.exports = config;
我想用config.serverBaseUrl
在另一个JS文件?我该怎么办?
我可以做
const config = require('./webpack.config.js')
和使用config这样
config.serverBaseUrl
UPDATE:
,如果我在另一个文件中 我得到这个使用const= require('config')
呃ROR
ERROR in ./app/components/ComponentBase.js
Module not found: Error: Cannot resolve module 'config' in /Users/username/data/projects/bwe_web/app/components
@ ./app/components/ComponentBase.js 33:13-30
看起来你已经在输出配置,为什么不只是需要配置? –
由于哟已经导出了'config',我相信如果你需要的话,你可以使用'config.serverBaseUrl'来获取它。 –
@DylanWright请参阅我的更新。我得到了一个错误'Module not found:Error:Can not resolve module'config'' – icn