Skip to content

Commit 5948f26

Browse files
committed
feat(webpack): default config
1 parent 3149aa9 commit 5948f26

File tree

6 files changed

+67
-65
lines changed

6 files changed

+67
-65
lines changed

helpers.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
var path = require('path');
22
var zlib = require('zlib');
3-
var validateWebpackConfig = require('webpack-validator');
3+
var webpackMerge = require('webpack-merge');
4+
var webpackDefaults = require('./webpack.default.conf.js');
5+
46

57
// Helper functions
68

7-
exports.validateWebpackConfig = validateWebpackConfig;
8-
exports.validate = validateWebpackConfig;
9+
function defaults(config) {
10+
return webpackMerge(webpackDefaults, config);
11+
}
12+
13+
function hasProcessFlag(flag) {
14+
return process.argv.join('').indexOf(flag) > -1;
15+
}
916

1017
function gzipMaxLevel(buffer, callback) {
1118
return zlib['gzip'](buffer, {level: 9}, callback)
1219
}
13-
exports.gzipMaxLevel = gzipMaxLevel;
1420

1521
function root(args) {
1622
args = Array.prototype.slice.call(arguments, 0);
1723
return path.join.apply(path, [__dirname].concat(args));
1824
}
19-
exports.root = root;
2025

2126
function rootNode(args) {
2227
args = Array.prototype.slice.call(arguments, 0);
2328
return root.apply(path, ['node_modules'].concat(args));
2429
}
25-
exports.rootNode = rootNode;
2630

2731
function prependExt(extensions, args) {
2832
args = args || [];
@@ -33,5 +37,11 @@ function prependExt(extensions, args) {
3337
}));
3438
}, ['']);
3539
}
40+
41+
exports.defaults = defaults;
42+
exports.hasProcessFlag = hasProcessFlag;
43+
exports.gzipMaxLevel = gzipMaxLevel;
44+
exports.root = root;
45+
exports.rootNode = rootNode;
3646
exports.prependExt = prependExt;
3747
exports.prepend = prependExt;

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@
9191
"url-loader": "^0.5.7",
9292
"webpack": "^1.12.14",
9393
"webpack-dev-server": "^1.14.1",
94-
"webpack-load-plugins": "^0.1.2",
9594
"webpack-md5-hash": "^0.0.5",
96-
"webpack-validator": "^1.0.0-beta.4"
95+
"webpack-merge": "^0.8.3"
9796
},
9897
"repository": {
9998
"type": "git",

webpack.config.js

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var CopyWebpackPlugin = require('copy-webpack-plugin');
77
var HtmlWebpackPlugin = require('html-webpack-plugin');
88

99
var ENV = process.env.ENV = process.env.NODE_ENV = 'development';
10-
var HMR = process.argv.join('').indexOf('hot') > -1;
10+
var HMR = helpers.hasProcessFlag('hot');
1111

1212
var metadata = {
1313
title: 'Angular2 Webpack Starter by @gdi2990 from @AngularClass',
@@ -19,28 +19,19 @@ var metadata = {
1919
};
2020
/*
2121
* Config
22+
* with default values at webpack.default.conf
2223
*/
23-
module.exports = helpers.validate({
24+
module.exports = helpers.defaults({
2425
// static data for index.html
2526
metadata: metadata,
26-
// for faster builds use 'eval'
27-
devtool: 'source-map',
28-
debug: true,
29-
// cache: false,
27+
// devtool: 'eval' // for faster builds use 'eval'
3028

3129
// our angular app
3230
entry: { 'polyfills': './src/polyfills.ts', 'main': './src/main.ts' },
3331

3432
// Config for our build files
3533
output: {
36-
path: helpers.root('dist'),
37-
filename: '[name].bundle.js',
38-
sourceMapFilename: '[name].map',
39-
chunkFilename: '[id].chunk.js'
40-
},
41-
42-
resolve: {
43-
extensions: ['', '.ts', '.async.ts', '.js']
34+
path: helpers.root('dist')
4435
},
4536

4637
module: {
@@ -83,20 +74,10 @@ module.exports = helpers.validate({
8374
],
8475

8576
// Other module loader config
86-
tslint: {
87-
emitErrors: false,
88-
failOnHint: false,
89-
resourcePath: 'src',
90-
},
9177

9278
// our Webpack Development Server config
9379
devServer: {
9480
port: metadata.port,
95-
host: metadata.host,
96-
// contentBase: 'src/',
97-
historyApiFallback: true,
98-
watchOptions: { aggregateTimeout: 300, poll: 1000 }
99-
},
100-
// we need this due to problems with es6-shim
101-
node: {global: 'window', progress: false, crypto: 'empty', module: false, clearImmediate: false, setImmediate: false}
81+
host: metadata.host
82+
}
10283
});

webpack.default.conf.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var path = require('path');
2+
3+
module.exports = {
4+
devtool: 'source-map',
5+
stats: { colors: true, reasons: true },
6+
resolve: {
7+
extensions: ['', '.ts', '.js']
8+
},
9+
debug: true,
10+
output: {
11+
filename: '[name].bundle.js',
12+
sourceMapFilename: '[name].map',
13+
chunkFilename: '[id].chunk.js'
14+
},
15+
module: {
16+
noParse: [
17+
path.join(__dirname, 'zone.js', 'dist'),
18+
path.join(__dirname, 'angular2', 'bundles')
19+
]
20+
},
21+
node: {
22+
global: 'window',
23+
progress: false,
24+
crypto: 'empty',
25+
module: false,
26+
clearImmediate: false,
27+
setImmediate: false
28+
},
29+
tslint: {
30+
emitErrors: false,
31+
failOnHint: false,
32+
resourcePath: 'src',
33+
},
34+
devServer: {
35+
historyApiFallback: true,
36+
watchOptions: {
37+
aggregateTimeout: 300,
38+
poll: 1000
39+
}
40+
}
41+
};

webpack.prod.config.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var metadata = {
3131
/*
3232
* Config
3333
*/
34-
module.exports = helpers.validate({
34+
module.exports = helpers.defaults({
3535
// static data for index.html
3636
metadata: metadata,
3737

@@ -54,8 +54,6 @@ module.exports = helpers.validate({
5454

5555
resolve: {
5656
cache: false,
57-
// ensure loader extensions match
58-
extensions: ['', '.ts','.js']
5957
},
6058

6159
module: {
@@ -193,13 +191,4 @@ module.exports = helpers.validate({
193191
},
194192
// don't use devServer for production
195193

196-
// we need this due to problems with es6-shim
197-
node: {
198-
global: 'window',
199-
progress: false,
200-
crypto: 'empty',
201-
module: false,
202-
clearImmediate: false,
203-
setImmediate: false
204-
}
205194
});

webpack.test.config.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ var ENV = process.env.ENV = process.env.NODE_ENV = 'test';
99
/*
1010
* Config
1111
*/
12-
module.exports = helpers.validate({
13-
resolve: {
14-
extensions: ['', '.ts','.js']
15-
},
12+
module.exports = helpers.defaults({
1613
devtool: 'inline-source-map',
1714
module: {
1815
preLoaders: [
@@ -58,14 +55,8 @@ module.exports = helpers.validate({
5855
/node_modules/
5956
]
6057
}
61-
],
62-
noParse: [
63-
helpers.root('zone.js/dist'),
64-
helpers.root('angular2/bundles')
6558
]
6659
},
67-
stats: { colors: true, reasons: true },
68-
debug: false,
6960
plugins: [
7061
new DefinePlugin({
7162
// Environment helpers
@@ -83,14 +74,5 @@ module.exports = helpers.validate({
8374
'__param': 'ts-helper/param',
8475
})
8576
],
86-
// we need this due to problems with es6-shim
87-
node: {
88-
global: 'window',
89-
progress: false,
90-
crypto: 'empty',
91-
module: false,
92-
clearImmediate: false,
93-
setImmediate: false
94-
}
9577
});
9678

0 commit comments

Comments
 (0)