2016-05-12 112 views
1

使用Webpack,支持将代码拆分为不同的软件包。其中一个选项是指定一组您希望选择为分割点的模块。将导入的供应商文件拆分为供应商软件包

here摘自:

var webpack = require("webpack"); 
 

 
module.exports = { 
 
    entry: { 
 
    app: "./app.js", 
 
    vendor: ["jquery", "underscore", ...], 
 
    }, 
 
    output: { 
 
    filename: "bundle.js" 
 
    }, 
 
    plugins: [ 
 
    new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"vendor", /* filename= */"vendor.bundle.js") 
 
    ] 
 
};

这显示了如何打出模块,如jquery。然而,选择那些在更传统的设置存在像一些JavaScript库中没有的node_modules:

/src /lib /vendor /fooLibrary fooLibrary.js fooLibrary.css

我想什么是将这些文件移动到供应商的捆绑,但可以不知道如何指定这些文件在供应商入口点。

回答

1

您可以设置绝对路径到供应商的lib

var webpack = require("webpack"); 

module.exports = { 
    entry: { 
    app: "./server.js", 
    vendor: ["/mylib/"], 
    }, 
    output: { 
    filename: "bundle.js" 
    }, 
    plugins: [ 
    new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"vendor", /* filename= */"vendor.bundle.js") 
    ] 
}; 

和构建的WebPack从LIB ABS路径厂商捆绑。

enter image description here

但是进口只工作是否存在index.js,所以之前你应该重命名供应商档案模块与复制的WebPack插件index.js或使用例如一饮而尽任务的任何任务的脚本。