将变量注入webpack [英] Injecting variables into webpack
问题描述
我正在尝试将一个变量注入我的webpack包中的每个模块,以便获得每个文件的JS错误的调试信息。我启用了
I'm trying to inject a variable into each module within my webpack bundle in order to have debugging information for JS errors per file. I've enabled
node: {
__filename: true
}
在我的webpack.config中,但我想注入类似
in my webpack.config, but I would like to inject something like
var filename = 'My filename is: ' + __filename;
进入每个模块。我已经看到横幅插件与 raw
选项但似乎这只会在webpack闭包之外注入横幅而不是我想要的将脚本注入每个模块的结果。
into each module before compilation. I've seen the Banner Plugin with the raw
option but it seems this would only inject the banner outside of the webpack closure rather than my desired result of injecting script into each module.
推荐答案
我使用变量来解析我的 webpack.config.js
文件中的几个变量:
I use variables to resolve a couple of variables in my webpack.config.js
file:
plugins: [
new webpack.DefinePlugin({
ENVIRONMENT: JSON.stringify(process.env.NODE_ENV || 'development'),
VERSION: JSON.stringify(require('./package.json').version)
})
]
它可能不够动态,但如果是,那么你可以绕过那个加载器解决方案。
It might not be dynamic enough, but if it is, then you might be able to bypass that loader solution.
这篇关于将变量注入webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!