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