最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Multiple bundles with webpack - Stack Overflow

programmeradmin0浏览0评论

Let's say I have a library like this:

src
--- component1
-------- component1.scss
-------- component1.js   

--- component2
-------- component2.scss
-------- component2.js 

and I want to distribute each component as an independent bundle, not as a common bundle for the whole app (component1 + component2 + etc):

dist
--- component1
-------- bundle1.js  

--- component2
-------- bundle.js

Is this achievable with just only one webpack config file or do I need to define an entry/ouput for each component?

Thanks!

Let's say I have a library like this:

src
--- component1
-------- component1.scss
-------- component1.js   

--- component2
-------- component2.scss
-------- component2.js 

and I want to distribute each component as an independent bundle, not as a common bundle for the whole app (component1 + component2 + etc):

dist
--- component1
-------- bundle1.js  

--- component2
-------- bundle.js

Is this achievable with just only one webpack config file or do I need to define an entry/ouput for each component?

Thanks!

Share Improve this question edited Dec 22, 2016 at 14:00 Rob Lyndon 12.7k5 gold badges54 silver badges78 bronze badges asked Dec 22, 2016 at 13:48 TrajanTrajan 3701 gold badge3 silver badges8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 17

You can use several entry points to achive this and split your code to chunks

{
  entry: { a: "./a", b: "./b" },
  output: { filename: "[name].js" },
  plugins: [ new webpack.optimize.CommonsChunkPlugin("init.js") ]
}

https://webpack.js.org/concepts/output/#multiple-entry-points

发布评论

评论列表(0)

  1. 暂无评论