2016-07-12 18 views
2

Ich habe dynamische Import-Module mit gemeinsamen Abhängigkeit, und ich brauche common.js mit g.js (in diesem Beispiel), aber es funktioniert nicht, ich habe leere gemeinsame. Was ist los? Ich möchte gemeinsam mit g.jswebpack 2 lazy loading

index.js

System.import("./d") 
    .then((module) => { 

    }); 

System.import("./t") 
    .then((module) => { 

    }); 

t.js

import "./g"; 

module.exports = { 
    x: 5 
} 

d.js

import "./g"; 

export function message() { 
    alert("msg") 
} 

webpack.config.js

module.exports = { 
    entry: {index: "./index.js"}, 
    context: __dirname, 
    output: { 
     filename: "dist/[name].js" 
    }, 
    resolve: { 
     modules: [ 
      "bower_components", 
      path.resolve('./'), 
     ], 
    }, 
    plugins: [ 
     new webpack.optimize.CommonsChunkPlugin({ 
      name: `common`, 
      async: true 
     }) 
    ] 
}; 

Antwort

0
module.exports = { 
    entry: {index: "./index.js"}, 
    context: __dirname, 
    output: { 
     filename: "dist/[name].js" 
    }, 
    resolve: { 
     modules: [ 
      "bower_components", 
      path.resolve('./'), 
     ], 
    }, 
    plugins: [ 
     new webpack.optimize.CommonsChunkPlugin({ 
       children: true, 
       async: true, 
      })) 
    ] 
};