簡體   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