This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.dev.js
191 lines (132 loc) · 4.38 KB
/
webpack.config.dev.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var url = require('url');
var { common, buildDefines } = require('./webpack.common.js');
// ensure development environment
process.env.NODE_ENV = 'development';
// detect development mode from environment
var devMode = process.env.DEV_MODE;
if (['build', 'reload'].indexOf(devMode) < 0) {
devMode = 'build';
}
var config = {
// Makes sure errors in console map to the correct file and line number
// Makes sure that breakpoints are hit, and variable values are shown
// 'cheap-module-eval-source-map' is quicker, but breakpoints don't work
devtool: 'source-map',
// No need to set `context`, base directory for resolving entry points:
// entry point paths are relative to current directory
entry: {
'vendor': common.relPaths.vendorEntryJit,
// Client application main entry point
'main': common.relPaths.mainEntryJit,
},
output: {
// The output directory as absolute path (required), where build artifacts are saved
path: common.absPaths.buildOutput,
// A template for the name of each output file on disk, as a relative path
filename: common.relPaths.bundleJs,
// A template for the name of each source-map file, as a relative path
// Leave default one
// A template for the name of each intermediate chunk file, as a relative path
chunkFilename: common.relPaths.chunk,
publicPath: common.urls.public,
// Include comments with information about the modules
pathinfo: true,
},
module: {
rules: [
// Pre-loaders
// none
// Loaders
common.rules.typescript.jit,
common.rules.sass.global,
common.rules.sass.component,
common.rules.css.global,
common.rules.css.component,
common.rules.html,
// Post-loaders
// none
],
// speed up build by excluding some big libraries from parsing
noParse: common.noParse,
},
resolve: {
extensions: common.resolve.extensions,
},
plugins: [
new webpack.DefinePlugin(buildDefines()),
// Provides context to Angular's use of System.import
new webpack.ContextReplacementPlugin(
common.patterns.angularContext,
common.absPaths.clientSrc,
{}
),
new webpack.optimize.CommonsChunkPlugin({
name: ['main', 'vendor'],
filename: common.relPaths.bundleJs,
minChunks: Infinity,
}),
new ExtractTextPlugin(common.relPaths.bundleCss),
// Only emit files when there are no errors
new webpack.NoEmitOnErrorsPlugin(),
// Copy static assets from their folder to common output folder
new CopyWebpackPlugin([{
from: common.absPaths.staticFiles,
}]),
],
};
// differences when reloading in development
if (devMode == 'reload') {
var protocol = 'http';
var hostname = 'localhost';
var defaultServerUrl = url.format({
protocol: protocol,
hostname: hostname,
port: common.ports.default,
});
var reloadServerUrl = url.format({
protocol: protocol,
hostname: hostname,
port: common.ports.reload,
});
// webpack dev server configuration
config.devServer = {
port: common.ports.reload,
// webpack dev server will serve bundles from memory at this relative URL path
publicPath: common.urls.public,
// webpack dev server will serve files from this directory
contentBase: common.relPaths.localDevRoot,
proxy: {
// proxied to backend web server
'/' : {
target: defaultServerUrl,
secure: false,
prependPath: false,
},
},
// For automatic page refresh, enable the 'webpack-dev-server/client?...' entry
inline: true,
// Enable Hot Module Replacement
hot: true,
// Set this as true if you want to access dev server from arbitrary url.
// This is handy if you are using a html5 router.
historyApiFallback: true,
watchOptions: { aggregateTimeout: 300, poll: 1000 },
// The rest is terminal configuration
console: true,
colors: true,
progress: true,
quiet: false,
displayErrorDetails: true,
displayCached: true,
noInfo: true,
stats: { colors: true },
};
config.plugins.push(
// We have to manually add the Hot Replacement plugin when running from Node
new webpack.HotModuleReplacementPlugin()
);
};
module.exports = config;