By
Lee Blazek
www.berzerk.io
Angular, Mean Stack, Front-end, Node api's, with a side of iOS
(by day)
Building apps/api's for public and canvaser's
Colorado Care
Amendment 69
on the November 2016
"Health Care is a Human Right,
not a commodity to be bought, sold, and traded!!"
(by night)
Existing module bundlers are not well suited for big projects (big single page applications). The most pressing reason for developing another module bundler was Code Splitting and that static assets should fit seamlessly together through modularization.
| Grunt | Gulp | Webpack | |
|---|---|---|---|
| code size | lots | medium | slim |
| ? | Configures individual task | + based on node streams and piping | tasks with hot reloading so you don't need watchers |
| live reloading | with plugins | with plugins | yes(web-pack-dev-server) |
| hot replacement | no | maybe? | yes |
| bundling (for lazy loading, js assets) |
needs browserify, requierejs, or other | needs browserify, requierejs, or other | yes, out of the box |
| modular styles (css, sass, etc) |
no | no | yes |
| modular assets (images, fonts, etc) | no | no | yes |
| project organization | traverse file/folder structure | traverse file/folder structure | entry points in code |
//webpack.config.js
module.exports = {
entry: './src/app.js',
output: {
path: './bin',
filename: 'app.bundle.js'
}
};
Loaders are special modules webpack uses to ‘load’ other modules (written in another language) into JavaScript (that webpack understands). For example, babel-loader uses Babel to load ES2015 files.
*install via NPM
Usually you’ll want to do some additional processing of the bundle in your workflow. An example would be minifying your file so that clients can load it faster. This can be done with plugins. We’ll add the uglify plugin to our configuration:
*Lots built in
//webpack.config.js
module.exports = {
//... previous code
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
}]
}
};
//webpack.config.js module.exports = { //... previous code plugins: [ new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false, }, output: { comments: false, }, }), ]
};
| { | |
| test: /\.css$/, | |
| loader: 'style!css', | |
| exclude: /node_modules/ | |
| }, | |
| { | |
| test: /\.scss$/, | |
| loader: 'style!css!sass', | |
| exclude: /node_modules/ | |
| }, | |
| { | |
| test: /\.(png|jpg)$/, | |
| loader: 'url?limit=25000', | |
| exclude: /node_modules/ | |
| }, | |
| { | |
| test: /\.html$/, | |
| loader: 'raw', | |
| exclude: /node_modules/ | |
| } |
require(./module.js) require(./module.sass) require(./module.html) or in ES6 regular import statements import './module.js'
new webpack.DefinePlugin({
ON_DEMO: process.env.NODE_ENV === 'demo'
}),
if(ON_DEMO){
angular.module('myApp').config(
require('./page4/page4.config').default
);