我想在webpack配置期间设置API URL。
尝试这样:
plugins.push(
new HtmlWebpackPlugin({
hash: true,
filename: 'index.html',
template: './src/index.ejs',
inject : false
}),
// Write out CSS bundle to its own file:
new ExtractTextPlugin({
filename: 'css/styles.css',
allChunks: true
}),
new webpack.DefinePlugin({
'process.env.API': 'api'
})
);
然后在我的JS中尝试将其称为
const accountCentreAPI = process.env.API;
但是得到如下错误:
http://localhost:8080/
webpack result is served from http://localhost:8080/
content is served from ./src
webpack: wait until bundle finished: /
{ SyntaxError: Unexpected token (1:49)
at Parser.pp$4.raise (F:\src\Client\node_modules\acorn\dist\acorn.js:2221:15)
at Parser.pp.unexpected (F:\src\Client\node_modules\acorn\dist\acorn.js:603:10)
at Parser.pp$3.parseExprAtom (F:\src\Client\node_modules\acorn\dist\acorn.js:1822:12)
我的网络版 版本:webpack 2.1.0-beta.22
注意一切正常,直到我在我的webpack中添加了DefinePlugin并尝试在我的js中调用process.env。