Reputation: 1930
TL;DR at the bottom.
I'm looking for a way to use Webpack like the way I'm using a Gulpfile right now.
My Gulpfile does the following:
app
files, they are page specific and can be loaded on demand).So now I have 3 types of files:
'framework'
'Library'
, it mostly looks for data-attributes on elements and binds datepickers, tooltips but also provides some utility functions like cleaning Strings, formatting Strings as money etc.I've watched a couple of video tutorials about it, I can see it is powerful and can help me to get further into JavaScript (read: use a more advanced structure and ES2015). I've also read through the Webpack tutorial but can't find how to make it work for my structure.
So the question is:
How can I use Webpack to have global (application wide) AND page-specific JavaScript in my applications and have them use third-party vendors (like jQuery, MomentJS, either through bower or npm or something).
Upvotes: 4
Views: 1342
Reputation: 2860
You should have a entry config for each page like this:
entry: {
page1: ['./src/page1.js'],
page2: ['./src/page2.js'],
}
And output like:
output: {
path: `${__dirname}/app/`,
filename: '[name].min.js',
},
And then use the CommonsChunkPlugin plugin to build a global file with things like jQuery, MomentJS
plugins: [
new webpack.optimize.CommonsChunkPlugin('vendors.and.lib.min.js'),
]
(This is for webpack version 1)
Upvotes: 4