繁体   English   中英

如何在bundle中排除js文件并在另一个chunk / bundle中使用它?

[英]how to exclude js file in bundle and use it in a different chunk/bundle instead?

我目前在js文件中有一些变量,并希望将它放在我的主app.bundle.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"
  }]

最后我有一个想要使用config.js的src / file.js(我现在正在这样做,但我不确定这是否正确)

import { url1, url2} from '../../config.js';

我的应用程序包将捆绑从我的index.js扩展的所有js文件(这是我的/ src .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副本

添加CommonChunksPlugin解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM