forked from e-schultz/ng2-redux-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
120 lines (112 loc) · 3.05 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict';
const path = require('path');
const proxy = require('./server/webpack-dev-proxy');
const loaders = require('./webpack/loaders');
const plugins = require('./webpack/plugins');
/*
* Dev Config
* ==========
*
* For dev, create an app entry point and a polyfills entry point
* (need to because it lives in a file that is never imported by the app -
* we bring it in later via CommonsChunkPlugin).
*
* Also, save compilation time by not adding [chunkhash]es to the filenames
*/
const devConfig = {
entry: {
app: './src/index.ts',
polyfills: './src/polyfills.ts',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
publicPath: '/',
sourceMapFilename: '[name].js.map',
chunkFilename: '[id].chunk.js',
},
devtool: 'inline-source-map',
};
/*
* Prod Config
* ===========
*
* For prod, create an app entry point and a polyfills entry point
* (need to because it lives in a file that is never imported by the app - we
* bring it in later via CommonsChunkPlugin) as well as a vendor bundle.
*
* The idea is that eventually, once chunk-manifest-webpack-plugin is
* working with wp2, each chunk suffixed with its chunkhash can be
* cached on a user's browser, ideally requiring them to only redownload
* the vendor bundle if the vendor libraries change. Otherwise, the
* smallest bundle, app.ts, would be the only thing they'd have to get a
* new version of, since it's the most likely to change.
*
* https://medium.com/@okonetchnikov/long-term-caching-of-static-assets
* -with-webpack-1ecb139adb95
*/
const prodConfig = {
entry: {
app: './src/index.ts',
// keep polyfills
polyfills: './src/polyfills.ts',
// and vendor files separate
vendor: [
'@angular/core',
'@angular/common',
'@angular/forms',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'rxjs',
'@angular-redux/store',
'@angular-redux/router',
'redux',
'immutable',
'redux-localstorage',
'redux-observable',
'redux-logger',
'typed-immutable-record',
],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[chunkhash].js',
publicPath: '/',
sourceMapFilename: '[name].[chunkhash].js.map',
chunkFilename: '[id].chunk.js',
},
devtool: 'source-map',
};
const baseConfig = {
resolve: {
extensions: ['.webpack.js', '.web.js', '.ts', '.js'],
},
plugins: plugins,
devServer: {
historyApiFallback: { index: '/' },
proxy: Object.assign({}, proxy(), { '/api/*': 'http://localhost:3000' }),
},
module: {
rules: [
loaders.tslint,
loaders.angular,
loaders.ts,
loaders.html,
loaders.css,
loaders.svg,
loaders.eot,
loaders.woff,
loaders.woff2,
loaders.ttf,
loaders.json,
],
noParse: [ /zone\.js\/dist\/.+/, /angular2\/bundles\/.+/ ],
},
};
module.exports = Object.assign(
{},
process.env.NODE_ENV === 'production' ? prodConfig : devConfig,
baseConfig
);