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