]>
Commit | Line | Data |
---|---|---|
4a6995be C |
1 | const helpers = require('./helpers') |
2 | const webpackMerge = require('webpack-merge') // used to merge webpack configs | |
cc3e2d9b | 3 | const webpackMergeDll = webpackMerge.strategy({plugins: 'replace'}) |
4a6995be C |
4 | const commonConfig = require('./webpack.common.js') // the settings that are common to prod and dev |
5 | ||
6 | /** | |
7 | * Webpack Plugins | |
8 | */ | |
cc3e2d9b | 9 | const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin') |
4a6995be | 10 | const DefinePlugin = require('webpack/lib/DefinePlugin') |
ab32b0fc | 11 | const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin') |
4d19d2f1 | 12 | const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin') |
4a6995be C |
13 | |
14 | /** | |
15 | * Webpack Constants | |
16 | */ | |
17 | const ENV = process.env.ENV = process.env.NODE_ENV = 'development' | |
ab32b0fc C |
18 | const HOST = process.env.HOST || 'localhost' |
19 | const PORT = process.env.PORT || 3000 | |
4a6995be | 20 | const HMR = helpers.hasProcessFlag('hot') |
2e92c10b | 21 | const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, { |
ab32b0fc C |
22 | host: HOST, |
23 | port: PORT, | |
4a6995be C |
24 | ENV: ENV, |
25 | HMR: HMR | |
26 | }) | |
27 | ||
cc3e2d9b C |
28 | const DllBundlesPlugin = require('webpack-dll-bundles-plugin').DllBundlesPlugin |
29 | ||
4a6995be C |
30 | /** |
31 | * Webpack configuration | |
32 | * | |
33 | * See: http://webpack.github.io/docs/configuration.html#cli | |
34 | */ | |
f9b2d2ce | 35 | module.exports = function (env) { |
c16ce1de | 36 | return webpackMerge(commonConfig({ env: ENV }), { |
4a6995be | 37 | /** |
4d19d2f1 C |
38 | * Developer tool to enhance debugging |
39 | * | |
40 | * See: http://webpack.github.io/docs/configuration.html#devtool | |
41 | * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps | |
42 | */ | |
f9b2d2ce | 43 | devtool: 'cheap-module-source-map', |
4a6995be | 44 | |
f9b2d2ce | 45 | /** |
4d19d2f1 C |
46 | * Options affecting the output of the compilation. |
47 | * | |
48 | * See: http://webpack.github.io/docs/configuration.html#output | |
49 | */ | |
f9b2d2ce C |
50 | output: { |
51 | /** | |
4d19d2f1 C |
52 | * The output directory as absolute path (required). |
53 | * | |
54 | * See: http://webpack.github.io/docs/configuration.html#output-path | |
55 | */ | |
f9b2d2ce C |
56 | path: helpers.root('dist'), |
57 | ||
58 | /** | |
4d19d2f1 C |
59 | * Specifies the name of each output file on disk. |
60 | * IMPORTANT: You must not specify an absolute path here! | |
61 | * | |
62 | * See: http://webpack.github.io/docs/configuration.html#output-filename | |
63 | */ | |
f9b2d2ce C |
64 | filename: '[name].bundle.js', |
65 | ||
66 | /** | |
4d19d2f1 C |
67 | * The filename of the SourceMaps for the JavaScript files. |
68 | * They are inside the output.path directory. | |
69 | * | |
70 | * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename | |
71 | */ | |
f9b2d2ce C |
72 | sourceMapFilename: '[name].map', |
73 | ||
74 | /** The filename of non-entry chunks as relative path | |
4d19d2f1 C |
75 | * inside the output.path directory. |
76 | * | |
77 | * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename | |
78 | */ | |
f9b2d2ce C |
79 | chunkFilename: '[id].chunk.js', |
80 | ||
81 | library: 'ac_[name]', | |
4d19d2f1 | 82 | libraryTarget: 'var', |
ab32b0fc | 83 | |
4d19d2f1 | 84 | publicPath: '/client/' |
f9b2d2ce | 85 | }, |
4a6995be | 86 | |
f9b2d2ce C |
87 | externals: { |
88 | webtorrent: 'WebTorrent' | |
89 | }, | |
4a6995be | 90 | |
f9b2d2ce C |
91 | plugins: [ |
92 | ||
93 | /** | |
4d19d2f1 C |
94 | * Plugin: DefinePlugin |
95 | * Description: Define free variables. | |
96 | * Useful for having development builds with debug logging or adding global constants. | |
97 | * | |
98 | * Environment helpers | |
99 | * | |
100 | * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin | |
101 | */ | |
f9b2d2ce C |
102 | // NOTE: when adding more properties, make sure you include them in custom-typings.d.ts |
103 | new DefinePlugin({ | |
104 | 'ENV': JSON.stringify(METADATA.ENV), | |
105 | 'HMR': METADATA.HMR, | |
106 | 'process.env': { | |
107 | 'ENV': JSON.stringify(METADATA.ENV), | |
108 | 'NODE_ENV': JSON.stringify(METADATA.ENV), | |
109 | 'HMR': METADATA.HMR | |
110 | } | |
111 | }), | |
7f82b8ae | 112 | |
cc3e2d9b C |
113 | new DllBundlesPlugin({ |
114 | bundles: { | |
115 | polyfills: [ | |
116 | 'core-js', | |
117 | { | |
118 | name: 'zone.js', | |
119 | path: 'zone.js/dist/zone.js' | |
120 | }, | |
121 | { | |
122 | name: 'zone.js', | |
123 | path: 'zone.js/dist/long-stack-trace-zone.js' | |
124 | }, | |
125 | 'ts-helpers' | |
126 | ], | |
127 | vendor: [ | |
128 | '@angular/platform-browser', | |
129 | '@angular/platform-browser-dynamic', | |
130 | '@angular/core', | |
131 | '@angular/common', | |
132 | '@angular/forms', | |
133 | '@angular/http', | |
134 | '@angular/router', | |
135 | '@angularclass/hmr', | |
136 | 'rxjs' | |
137 | ] | |
138 | }, | |
139 | dllDir: helpers.root('dll'), | |
140 | webpackConfig: webpackMergeDll(commonConfig({env: ENV}), { | |
141 | devtool: 'cheap-module-source-map', | |
142 | plugins: [] | |
143 | }) | |
144 | }), | |
145 | ||
146 | /** | |
147 | * Plugin: AddAssetHtmlPlugin | |
148 | * Description: Adds the given JS or CSS file to the files | |
149 | * Webpack knows about, and put it into the list of assets | |
150 | * html-webpack-plugin injects into the generated html. | |
151 | * | |
152 | * See: https://github.com/SimenB/add-asset-html-webpack-plugin | |
153 | */ | |
154 | new AddAssetHtmlPlugin([ | |
155 | { filepath: helpers.root(`dll/${DllBundlesPlugin.resolveFile('polyfills')}`) }, | |
156 | { filepath: helpers.root(`dll/${DllBundlesPlugin.resolveFile('vendor')}`) } | |
157 | ]), | |
158 | ||
4d19d2f1 C |
159 | /** |
160 | * Plugin: NamedModulesPlugin (experimental) | |
161 | * Description: Uses file names as module name. | |
162 | * | |
163 | * See: https://github.com/webpack/webpack/commit/a04ffb928365b19feb75087c63f13cadfc08e1eb | |
164 | */ | |
165 | new NamedModulesPlugin(), | |
166 | ||
167 | /** | |
168 | * Plugin LoaderOptionsPlugin (experimental) | |
169 | * | |
170 | * See: https://gist.github.com/sokra/27b24881210b56bbaff7 | |
171 | */ | |
172 | new LoaderOptionsPlugin({ | |
173 | debug: true, | |
174 | options: { | |
175 | ||
176 | /** | |
177 | * Static analysis linter for TypeScript advanced options configuration | |
178 | * Description: An extensible linter for the TypeScript language. | |
179 | * | |
180 | * See: https://github.com/wbuchwalter/tslint-loader | |
181 | */ | |
182 | tslint: { | |
183 | emitErrors: false, | |
184 | failOnHint: false, | |
185 | resourcePath: 'src' | |
186 | }, | |
187 | ||
188 | // FIXME: Remove | |
189 | // https://github.com/bholloway/resolve-url-loader/issues/36 | |
190 | // https://github.com/jtangelder/sass-loader/issues/289 | |
191 | context: __dirname, | |
192 | output: { | |
193 | path: helpers.root('dist') | |
194 | } | |
195 | ||
196 | } | |
197 | }) | |
198 | ||
f9b2d2ce | 199 | ], |
4a6995be C |
200 | |
201 | /** | |
4d19d2f1 C |
202 | * Webpack Development Server configuration |
203 | * Description: The webpack-dev-server is a little node.js Express server. | |
204 | * The server emits information about the compilation state to the client, | |
205 | * which reacts to those events. | |
206 | * | |
207 | * See: https://webpack.github.io/docs/webpack-dev-server.html | |
208 | */ | |
f9b2d2ce C |
209 | devServer: { |
210 | port: METADATA.port, | |
211 | host: METADATA.host, | |
212 | historyApiFallback: true, | |
213 | watchOptions: { | |
214 | aggregateTimeout: 300, | |
215 | poll: 1000 | |
216 | }, | |
217 | outputPath: helpers.root('dist') | |
218 | }, | |
219 | ||
220 | /* | |
4d19d2f1 C |
221 | * Include polyfills or mocks for various node stuff |
222 | * Description: Node configuration | |
223 | * | |
224 | * See: https://webpack.github.io/docs/configuration.html#node | |
225 | */ | |
f9b2d2ce | 226 | node: { |
4d19d2f1 | 227 | global: true, |
f9b2d2ce C |
228 | crypto: 'empty', |
229 | process: true, | |
230 | module: false, | |
231 | clearImmediate: false, | |
232 | setImmediate: false | |
233 | } | |
234 | }) | |
235 | } |