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