2016-09-06 7 views
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を持っています私のアプリ束W

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

それは(私は現在、これをやっているが、これが正しいかどうか、私にはわからない)config.jsのを使用したいです私のindex.jsから展開されたすべてのjsファイルをバンドルします(これはすべてmy/src .jsファイルです)。 私のconfig.jsはsrcフォルダの外ですが、srcのjsファイルの1つに、config.jsで設定した変数を使用します。

私の結果は、変数とともにconf.bundle.jsを生成しますが、app.bundle.jsにもバンドルされているようです。

だから今、私の質問は、追加

答えて

0

私はapp.bundle.jsであるconfig.jsのコピーをせずに私のapp.bundle.js上config.bundle.js変数を使用することができるだろうかですCommonChunksPluginはこの問題を解決します。

+0

なぜそれが問題を解決するのかを説明するといいでしょう。リンクのみの回答は面倒です。 – ceebreenk

関連する問題