0
我目前有一个js文件中的几个变量,并希望将它放在我的主app.bundle.js之外的它自己的包中。如何排除捆绑中的js文件并将其用于不同的块/捆绑包中?
config.js
export const url1= 'testing1';
export const url2= 'test2';
我有这样一个非常基本的WebPack并添加新条目(这只是一个例子)
module.exports = {
{
entry: {
app: [path.resolve(__dirname, './src/index.js')],
config: [path.resolve(__dirname, './config.js')] <---here
},
output: {
filename: '[name].js',
path: __dirname + '/built'
}
}
module.loaders: [
{
// "test" is commonly used to match the file extension
test: /\.jsx$/,
// "include" is commonly used to match the directories
include: [
path.resolve(__dirname, "app/src"),
path.resolve(__dirname, "app/test")
],
// "exclude" should be used to exclude exceptions
// try to prefer "include" when possible
// the "loader"
loader: "babel-loader"
}]
最后我有一个src/file.js想要使用config.js(我目前正在这样做,但我不知道这是否正确)
import { url1, url2} from '../../config.js';
我的应用程序包w病毒捆绑从我的index.js(这是所有my/src .js文件)扩展的所有js文件。 我的config.js位于src文件夹之外,但是我希望我的一个来自src的js文件能够使用我在config.js中设置的那些变量。
我的结果确实产生了一个带变量的conf.bundle.js,但它似乎也被捆绑到了app.bundle.js中。
所以现在我的问题是如何将我能够用我的app.bundle.js变量config.bundle.js没有在app.bundle.js有config.js的副本
这将是很好的解释为什么它解决了这个问题。链接只有答案很麻烦。 – ceebreenk