generator-folklore 3.0.0-alpha.0 → 3.0.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/generators/babel/index.js +2 -4
- package/lib/generators/browserslist/templates/browserslistrc +8 -8
- package/lib/generators/build/index.js +45 -243
- package/lib/generators/docs/index.js +2 -6
- package/lib/generators/eslint/index.js +2 -10
- package/lib/generators/js/index.js +2 -6
- package/lib/generators/laravel-panneau/index.js +1 -3
- package/lib/generators/lerna-repository/index.js +1 -3
- package/lib/generators/npm-package/index.js +2 -6
- package/lib/generators/prettier/index.js +35 -0
- package/lib/generators/{eslint → prettier}/templates/prettierrc.json +0 -0
- package/lib/generators/react-package/index.js +2 -6
- package/lib/generators/storybook/index.js +1 -3
- package/lib/generators/stylelint/index.js +2 -4
- package/lib/generators/test/index.js +1 -3
- package/package.json +2 -2
- package/lib/generators/build/templates/config.js +0 -78
- package/lib/generators/build/templates/env.js +0 -90
- package/lib/generators/build/templates/paths.js +0 -92
- package/lib/generators/build/templates/polyfills.js +0 -25
- package/lib/generators/build/templates/postcss.config.js +0 -12
- package/lib/generators/build/templates/scripts/build.js +0 -158
- package/lib/generators/build/templates/scripts/imagemin.js +0 -59
- package/lib/generators/build/templates/scripts/modernizr.js +0 -22
- package/lib/generators/build/templates/scripts/server.js +0 -176
- package/lib/generators/build/templates/utils/getConfigValue.js +0 -5
- package/lib/generators/build/templates/utils/getLocalIdent.js +0 -11
- package/lib/generators/build/templates/webpack.config.dev.js +0 -394
- package/lib/generators/build/templates/webpack.config.prod.js +0 -571
- package/lib/generators/build/templates/webpackDevServer.config.js +0 -109
@@ -1,571 +0,0 @@
|
|
1
|
-
/* eslint-disable no-console */
|
2
|
-
const path = require('path');
|
3
|
-
const webpack = require('webpack');
|
4
|
-
const PnpWebpackPlugin = require('pnp-webpack-plugin');
|
5
|
-
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
6
|
-
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
|
7
|
-
const ManifestPlugin = require('webpack-manifest-plugin');
|
8
|
-
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
9
|
-
const TerserPlugin = require('terser-webpack-plugin');
|
10
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
11
|
-
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
12
|
-
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
|
13
|
-
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
|
14
|
-
const safePostCssParser = require('postcss-safe-parser');
|
15
|
-
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
16
|
-
const paths = require('./paths');
|
17
|
-
const config = require('./config').webpack;
|
18
|
-
const getLocalIdent = require('./utils/getLocalIdent');
|
19
|
-
const getConfigValue = require('./utils/getConfigValue');
|
20
|
-
const getClientEnvironment = require('./env');
|
21
|
-
|
22
|
-
// Webpack uses `publicPath` to determine where the app is being served from.
|
23
|
-
// It requires a trailing slash, or the file assets will get an incorrect path.
|
24
|
-
const publicPath = paths.servedPath;
|
25
|
-
// Some apps do not use client-side routing with pushState.
|
26
|
-
// For these, "homepage" can be set to "." to enable relative asset paths.
|
27
|
-
const shouldUseRelativeAssetPaths = publicPath === './';
|
28
|
-
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
29
|
-
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
30
|
-
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
|
31
|
-
// makes for a smoother build process.
|
32
|
-
const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
|
33
|
-
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
34
|
-
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
35
|
-
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
36
|
-
const publicUrl = publicPath.slice(0, -1);
|
37
|
-
// Get environment variables to inject into our app.
|
38
|
-
const env = getClientEnvironment(publicUrl);
|
39
|
-
|
40
|
-
const hasHtml = (paths.appHtml || null) !== null;
|
41
|
-
|
42
|
-
// Assert this just to be safe.
|
43
|
-
// Development builds of React are slow and not intended for production.
|
44
|
-
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
|
45
|
-
throw new Error('Production builds must have NODE_ENV=production.');
|
46
|
-
}
|
47
|
-
|
48
|
-
// Note: defined here because it will be used more than once.
|
49
|
-
const cssFilename = getConfigValue(config.cssFilename);
|
50
|
-
|
51
|
-
// Note: defined here because it will be used more than once.
|
52
|
-
const cssChunkFilename = getConfigValue(config.cssChunkFilename);
|
53
|
-
|
54
|
-
// Options for PostCSS as we reference these options twice
|
55
|
-
// Adds vendor prefixing based on your specified browser support in
|
56
|
-
// package.json
|
57
|
-
const postCSSLoaderOptions = {
|
58
|
-
config: {
|
59
|
-
path: path.join(__dirname, './postcss.config.js'),
|
60
|
-
ctx: {
|
61
|
-
env,
|
62
|
-
},
|
63
|
-
},
|
64
|
-
sourceMap: shouldUseSourceMap,
|
65
|
-
};
|
66
|
-
|
67
|
-
// style files regexes
|
68
|
-
const cssRegex = getConfigValue(config.cssRegex);
|
69
|
-
const cssModuleRegex = getConfigValue(config.cssModuleRegex);
|
70
|
-
const sassRegex = getConfigValue(config.sassRegex);
|
71
|
-
const sassModuleRegex = getConfigValue(config.sassModuleRegex);
|
72
|
-
|
73
|
-
// common function to get style loaders
|
74
|
-
const getStyleLoaders = (cssOptions, preProcessor) => {
|
75
|
-
const loaders = [
|
76
|
-
{
|
77
|
-
loader: MiniCssExtractPlugin.loader,
|
78
|
-
options: Object.assign(
|
79
|
-
{},
|
80
|
-
shouldUseRelativeAssetPaths ? { publicPath: '../../' } : undefined,
|
81
|
-
),
|
82
|
-
},
|
83
|
-
{
|
84
|
-
loader: require.resolve('css-loader'),
|
85
|
-
options: cssOptions,
|
86
|
-
},
|
87
|
-
{
|
88
|
-
loader: require.resolve('postcss-loader'),
|
89
|
-
options: postCSSLoaderOptions,
|
90
|
-
},
|
91
|
-
];
|
92
|
-
if (preProcessor) {
|
93
|
-
loaders.push({
|
94
|
-
loader: require.resolve(preProcessor),
|
95
|
-
options: {
|
96
|
-
sourceMap: shouldUseSourceMap,
|
97
|
-
},
|
98
|
-
});
|
99
|
-
}
|
100
|
-
return loaders;
|
101
|
-
};
|
102
|
-
|
103
|
-
// This is the production configuration.
|
104
|
-
// It compiles slowly and is focused on producing a fast and minimal bundle.
|
105
|
-
// The development configuration is different and lives in a separate file.
|
106
|
-
module.exports = {
|
107
|
-
mode: 'production',
|
108
|
-
// Don't attempt to continue if there are any errors.
|
109
|
-
bail: true,
|
110
|
-
// We generate sourcemaps in production. This is slow but gives good results.
|
111
|
-
// You can exclude the *.map files from the build during deployment.
|
112
|
-
devtool: shouldUseSourceMap ? 'source-map' : false,
|
113
|
-
// In production, we only want to load the polyfills and the app code.
|
114
|
-
entry: [paths.appIndexJs],
|
115
|
-
output: {
|
116
|
-
// The build folder.
|
117
|
-
path: paths.appBuild,
|
118
|
-
// Generated JS file names (with nested folders).
|
119
|
-
// There will be one main bundle, and one file per asynchronous chunk.
|
120
|
-
// We don't currently advertise code splitting but Webpack supports it.
|
121
|
-
filename: getConfigValue(config.filename),
|
122
|
-
// There are also additional JS chunk files if you use code splitting.
|
123
|
-
chunkFilename: getConfigValue(config.chunkFilename),
|
124
|
-
// We inferred the "public path" (such as / or /my-project) from homepage.
|
125
|
-
publicPath,
|
126
|
-
// Point sourcemap entries to original disk location (format as URL on Windows)
|
127
|
-
devtoolModuleFilenameTemplate: info => path.relative(paths.appSrc, info.absoluteResourcePath).replace(/\\/g, '/'),
|
128
|
-
},
|
129
|
-
optimization: {
|
130
|
-
minimizer: [
|
131
|
-
new TerserPlugin({
|
132
|
-
terserOptions: {
|
133
|
-
parse: {
|
134
|
-
// we want terser to parse ecma 8 code. However, we don't want it
|
135
|
-
// to apply any minfication steps that turns valid ecma 5 code
|
136
|
-
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
137
|
-
// sections only apply transformations that are ecma 5 safe
|
138
|
-
// https://github.com/facebook/create-react-app/pull/4234
|
139
|
-
ecma: 8,
|
140
|
-
},
|
141
|
-
compress: {
|
142
|
-
ecma: 5,
|
143
|
-
warnings: false,
|
144
|
-
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
145
|
-
// https://github.com/facebook/create-react-app/issues/2376
|
146
|
-
// Pending further investigation:
|
147
|
-
// https://github.com/mishoo/UglifyJS2/issues/2011
|
148
|
-
comparisons: false,
|
149
|
-
// Disabled because of an issue with Terser breaking valid code:
|
150
|
-
// https://github.com/facebook/create-react-app/issues/5250
|
151
|
-
// Pending futher investigation:
|
152
|
-
// https://github.com/terser-js/terser/issues/120
|
153
|
-
inline: 2,
|
154
|
-
},
|
155
|
-
mangle: {
|
156
|
-
safari10: true,
|
157
|
-
},
|
158
|
-
output: {
|
159
|
-
ecma: 5,
|
160
|
-
comments: false,
|
161
|
-
// Turned on because emoji and regex is not minified properly using default
|
162
|
-
// https://github.com/facebook/create-react-app/issues/2488
|
163
|
-
ascii_only: true,
|
164
|
-
},
|
165
|
-
},
|
166
|
-
// Use multi-process parallel running to improve the build speed
|
167
|
-
// Default number of concurrent runs: os.cpus().length - 1
|
168
|
-
parallel: true,
|
169
|
-
// Enable file caching
|
170
|
-
cache: true,
|
171
|
-
sourceMap: shouldUseSourceMap,
|
172
|
-
}),
|
173
|
-
new OptimizeCSSAssetsPlugin({
|
174
|
-
cssProcessorOptions: {
|
175
|
-
parser: safePostCssParser,
|
176
|
-
map: shouldUseSourceMap
|
177
|
-
? {
|
178
|
-
// `inline: false` forces the sourcemap to be output into a
|
179
|
-
// separate file
|
180
|
-
inline: false,
|
181
|
-
// `annotation: true` appends the sourceMappingURL to the end of
|
182
|
-
// the css file, helping the browser find the sourcemap
|
183
|
-
annotation: true,
|
184
|
-
}
|
185
|
-
: false,
|
186
|
-
},
|
187
|
-
}),
|
188
|
-
],
|
189
|
-
// Automatically split vendor and commons
|
190
|
-
// https://twitter.com/wSokra/status/969633336732905474
|
191
|
-
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
|
192
|
-
splitChunks: {
|
193
|
-
chunks: hasHtml ? 'all' : 'async',
|
194
|
-
name: false,
|
195
|
-
},
|
196
|
-
// Keep the runtime chunk seperated to enable long term caching
|
197
|
-
// https://twitter.com/wSokra/status/969679223278505985
|
198
|
-
runtimeChunk: hasHtml,
|
199
|
-
},
|
200
|
-
resolve: {
|
201
|
-
// This allows you to set a fallback for where Webpack should look for modules.
|
202
|
-
// We placed these paths second because we want `node_modules` to "win"
|
203
|
-
// if there are any conflicts. This matches Node resolution mechanism.
|
204
|
-
// https://github.com/facebook/create-react-app/issues/253
|
205
|
-
modules: ['node_modules'].concat(
|
206
|
-
// It is guaranteed to exist because we tweak it in `env.js`
|
207
|
-
process.env.NODE_PATH.split(path.delimiter).filter(Boolean),
|
208
|
-
),
|
209
|
-
// These are the reasonable defaults supported by the Node ecosystem.
|
210
|
-
// We also include JSX as a common component filename extension to support
|
211
|
-
// some tools, although we do not recommend using it, see:
|
212
|
-
// https://github.com/facebook/create-react-app/issues/290
|
213
|
-
// `web` extension prefixes have been added for better support
|
214
|
-
// for React Native Web.
|
215
|
-
extensions: paths.moduleFileExtensions.map(ext => `.${ext}`),
|
216
|
-
alias: {
|
217
|
-
// Support React Native Web
|
218
|
-
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
219
|
-
'react-native': 'react-native-web',
|
220
|
-
},
|
221
|
-
plugins: [
|
222
|
-
// Adds support for installing with Plug'n'Play, leading to faster installs and adding
|
223
|
-
// guards against forgotten dependencies and such.
|
224
|
-
PnpWebpackPlugin,
|
225
|
-
// Prevents users from importing files from outside of src/ (or node_modules/).
|
226
|
-
// This often causes confusion because we only process files within src/ with babel.
|
227
|
-
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
228
|
-
// please link the files into your node_modules/ and let module-resolution kick in.
|
229
|
-
// Make sure your source files are compiled, as they will not be processed in any way.
|
230
|
-
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
231
|
-
],
|
232
|
-
},
|
233
|
-
resolveLoader: {
|
234
|
-
plugins: [
|
235
|
-
// Also related to Plug'n'Play, but this time it tells Webpack to load its loaders
|
236
|
-
// from the current package.
|
237
|
-
PnpWebpackPlugin.moduleLoader(module),
|
238
|
-
],
|
239
|
-
},
|
240
|
-
module: {
|
241
|
-
strictExportPresence: true,
|
242
|
-
rules: [
|
243
|
-
// Disable require.ensure as it's not a standard language feature.
|
244
|
-
{ parser: { requireEnsure: false } },
|
245
|
-
|
246
|
-
// First, run the linter.
|
247
|
-
// It's important to do this before Babel processes the JS.
|
248
|
-
{
|
249
|
-
test: /\.(js|mjs|jsx)$/,
|
250
|
-
enforce: 'pre',
|
251
|
-
use: [
|
252
|
-
{
|
253
|
-
options: {
|
254
|
-
formatter: require.resolve('react-dev-utils/eslintFormatter'),
|
255
|
-
eslintPath: require.resolve('eslint'),
|
256
|
-
},
|
257
|
-
loader: require.resolve('eslint-loader'),
|
258
|
-
},
|
259
|
-
],
|
260
|
-
include: paths.appSrc,
|
261
|
-
},
|
262
|
-
{
|
263
|
-
// "oneOf" will traverse all following loaders until one will
|
264
|
-
// match the requirements. When no loader matches it will fall
|
265
|
-
// back to the "file" loader at the end of the loader list.
|
266
|
-
oneOf: [
|
267
|
-
// "url" loader works just like "file" loader but it also embeds
|
268
|
-
// assets smaller than specified size as data URLs to avoid requests.
|
269
|
-
{
|
270
|
-
test: [
|
271
|
-
/\.woff$/,
|
272
|
-
/\.woff2$/,
|
273
|
-
/\.otf$/,
|
274
|
-
/\.ttf$/,
|
275
|
-
/\.otf$/,
|
276
|
-
/\.eot$/,
|
277
|
-
/\.svg$/,
|
278
|
-
],
|
279
|
-
include: [/\/fonts\//],
|
280
|
-
loader: require.resolve('file-loader'),
|
281
|
-
options: {
|
282
|
-
limit: 10000,
|
283
|
-
name: getConfigValue(config.fontFilename),
|
284
|
-
},
|
285
|
-
},
|
286
|
-
{
|
287
|
-
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.svg$/],
|
288
|
-
loader: require.resolve('url-loader'),
|
289
|
-
options: {
|
290
|
-
limit: 10000,
|
291
|
-
name: getConfigValue(config.imageFilename),
|
292
|
-
},
|
293
|
-
},
|
294
|
-
// Process JS with Babel.
|
295
|
-
{
|
296
|
-
test: /\.(js|mjs|jsx|ts|tsx)$/,
|
297
|
-
include: paths.appSrc,
|
298
|
-
|
299
|
-
loader: require.resolve('babel-loader'),
|
300
|
-
options: {
|
301
|
-
customize: require.resolve('babel-preset-react-app/webpack-overrides'),
|
302
|
-
plugins: [
|
303
|
-
[
|
304
|
-
require.resolve('babel-plugin-named-asset-import'),
|
305
|
-
{
|
306
|
-
loaderMap: {
|
307
|
-
svg: {
|
308
|
-
ReactComponent:
|
309
|
-
'@svgr/webpack?-prettier,-svgo![path]',
|
310
|
-
},
|
311
|
-
},
|
312
|
-
},
|
313
|
-
],
|
314
|
-
],
|
315
|
-
cacheDirectory: true,
|
316
|
-
// Save disk space when time isn't as important
|
317
|
-
cacheCompression: true,
|
318
|
-
compact: true,
|
319
|
-
},
|
320
|
-
},
|
321
|
-
// For dependencies
|
322
|
-
{
|
323
|
-
test: /\.(js|mjs)$/,
|
324
|
-
exclude: /@babel(?:\/|\\{1,2})runtime/,
|
325
|
-
loader: require.resolve('babel-loader'),
|
326
|
-
options: {
|
327
|
-
babelrc: false,
|
328
|
-
configFile: false,
|
329
|
-
compact: false,
|
330
|
-
presets: [
|
331
|
-
[
|
332
|
-
require.resolve('babel-preset-react-app/dependencies'),
|
333
|
-
{ helpers: true },
|
334
|
-
],
|
335
|
-
],
|
336
|
-
cacheDirectory: true,
|
337
|
-
// Save disk space when time isn't as important
|
338
|
-
cacheCompression: true,
|
339
|
-
// If an error happens in a package, it's possible to be
|
340
|
-
// because it was compiled. Thus, we don't want the browser
|
341
|
-
// debugger to show the original code. Instead, the code
|
342
|
-
// being evaluated would be much more helpful.
|
343
|
-
sourceMaps: false,
|
344
|
-
},
|
345
|
-
},
|
346
|
-
// The notation here is somewhat confusing.
|
347
|
-
// "postcss" loader applies autoprefixer to our CSS.
|
348
|
-
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
349
|
-
// "style" loader normally turns CSS into JS modules injecting <style>,
|
350
|
-
// but unlike in development configuration, we do something different.
|
351
|
-
// `ExtractTextPlugin` first applies the "postcss" and "css" loaders
|
352
|
-
// (second argument), then grabs the result CSS and puts it into a
|
353
|
-
// separate file in our build process. This way we actually ship
|
354
|
-
// a single CSS file in production instead of JS code injecting <style>
|
355
|
-
// tags. If you use code splitting, however, any async bundles will still
|
356
|
-
// use the "style" loader inside the async code so CSS from them won't be
|
357
|
-
// in the main CSS file.
|
358
|
-
// By default we support CSS Modules with the extension .module.css
|
359
|
-
{
|
360
|
-
test: cssRegex,
|
361
|
-
loader: getStyleLoaders({
|
362
|
-
importLoaders: 1,
|
363
|
-
sourceMap: shouldUseSourceMap,
|
364
|
-
}),
|
365
|
-
// Don't consider CSS imports dead code even if the
|
366
|
-
// containing package claims to have no side effects.
|
367
|
-
// Remove this when webpack adds a warning or an error for this.
|
368
|
-
// See https://github.com/webpack/webpack/issues/6571
|
369
|
-
sideEffects: true,
|
370
|
-
},
|
371
|
-
// Adds support for CSS Modules (https://github.com/css-modules/css-modules)
|
372
|
-
// using the extension .module.css
|
373
|
-
{
|
374
|
-
test: cssModuleRegex,
|
375
|
-
exclude: cssRegex,
|
376
|
-
loader: getStyleLoaders({
|
377
|
-
importLoaders: 1,
|
378
|
-
sourceMap: shouldUseSourceMap,
|
379
|
-
modules: {
|
380
|
-
localIdentName: getConfigValue(config.cssLocalIdent),
|
381
|
-
// prettier-ignore
|
382
|
-
getLocalIdent: (context, localIdentName, localName) => (
|
383
|
-
getLocalIdent(localIdentName, localName, context.resourcePath)
|
384
|
-
),
|
385
|
-
},
|
386
|
-
}),
|
387
|
-
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
388
|
-
},
|
389
|
-
// Opt-in support for SASS. The logic here is somewhat similar
|
390
|
-
// as in the CSS routine, except that "sass-loader" runs first
|
391
|
-
// to compile SASS files into CSS.
|
392
|
-
// By default we support SASS Modules with the
|
393
|
-
// extensions .module.scss or .module.sass
|
394
|
-
{
|
395
|
-
test: sassRegex,
|
396
|
-
loader: getStyleLoaders(
|
397
|
-
{
|
398
|
-
importLoaders: 2,
|
399
|
-
sourceMap: shouldUseSourceMap,
|
400
|
-
},
|
401
|
-
'sass-loader',
|
402
|
-
),
|
403
|
-
// Don't consider CSS imports dead code even if the
|
404
|
-
// containing package claims to have no side effects.
|
405
|
-
// Remove this when webpack adds a warning or an error for this.
|
406
|
-
// See https://github.com/webpack/webpack/issues/6571
|
407
|
-
sideEffects: true,
|
408
|
-
},
|
409
|
-
// Adds support for CSS Modules, but using SASS
|
410
|
-
// using the extension .module.scss or .module.sass
|
411
|
-
{
|
412
|
-
test: sassModuleRegex,
|
413
|
-
exclude: sassRegex,
|
414
|
-
loader: getStyleLoaders(
|
415
|
-
{
|
416
|
-
importLoaders: 2,
|
417
|
-
sourceMap: shouldUseSourceMap,
|
418
|
-
modules: {
|
419
|
-
localIdentName: getConfigValue(config.cssLocalIdent),
|
420
|
-
// prettier-ignore
|
421
|
-
getLocalIdent: (context, localIdentName, localName) => (
|
422
|
-
getLocalIdent(
|
423
|
-
localIdentName,
|
424
|
-
localName,
|
425
|
-
context.resourcePath,
|
426
|
-
)
|
427
|
-
),
|
428
|
-
},
|
429
|
-
|
430
|
-
},
|
431
|
-
'sass-loader',
|
432
|
-
),
|
433
|
-
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
434
|
-
},
|
435
|
-
// "file" loader makes sure assets end up in the `build` folder.
|
436
|
-
// When you `import` an asset, you get its filename.
|
437
|
-
// This loader doesn't use a "test" so it will catch all modules
|
438
|
-
// that fall through the other loaders.
|
439
|
-
{
|
440
|
-
loader: require.resolve('file-loader'),
|
441
|
-
// Exclude `js` files to keep "css" loader working as it injects
|
442
|
-
// it's runtime that would otherwise processed through "file" loader.
|
443
|
-
// Also exclude `html` and `json` extensions so they get processed
|
444
|
-
// by webpacks internal loaders.
|
445
|
-
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.html\.ejs$/, /\.json$/],
|
446
|
-
options: {
|
447
|
-
name: getConfigValue(config.mediaFilename),
|
448
|
-
},
|
449
|
-
},
|
450
|
-
// ** STOP ** Are you adding a new loader?
|
451
|
-
// Make sure to add the new loader(s) before the "file" loader.
|
452
|
-
],
|
453
|
-
},
|
454
|
-
],
|
455
|
-
},
|
456
|
-
plugins: [
|
457
|
-
// Generates an `index.html` file with the <script> injected.
|
458
|
-
...(hasHtml
|
459
|
-
? [
|
460
|
-
new HtmlWebpackPlugin({
|
461
|
-
inject: true,
|
462
|
-
template: paths.appHtml,
|
463
|
-
minify: {
|
464
|
-
removeComments: true,
|
465
|
-
collapseWhitespace: true,
|
466
|
-
removeRedundantAttributes: true,
|
467
|
-
useShortDoctype: true,
|
468
|
-
removeEmptyAttributes: true,
|
469
|
-
removeStyleLinkTypeAttributes: true,
|
470
|
-
keepClosingSlash: true,
|
471
|
-
minifyJS: true,
|
472
|
-
minifyCSS: true,
|
473
|
-
minifyURLs: true,
|
474
|
-
},
|
475
|
-
}),
|
476
|
-
]
|
477
|
-
: []),
|
478
|
-
// Inlines the webpack runtime script. This script is too small to warrant
|
479
|
-
// a network request.
|
480
|
-
shouldInlineRuntimeChunk
|
481
|
-
&& new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime~.+[.]js/]),
|
482
|
-
// Makes some environment variables available in index.html.
|
483
|
-
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
484
|
-
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
485
|
-
// In production, it will be an empty string unless you specify "homepage"
|
486
|
-
// in `package.json`, in which case it will be the pathname of that URL.
|
487
|
-
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
|
488
|
-
// This gives some necessary context to module not found errors, such as
|
489
|
-
// the requesting resource.
|
490
|
-
new ModuleNotFoundPlugin(paths.appPath),
|
491
|
-
// Makes some environment variables available to the JS code, for example:
|
492
|
-
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
493
|
-
// It is absolutely essential that NODE_ENV was set to production here.
|
494
|
-
// Otherwise React will be compiled in the very slow development mode.
|
495
|
-
new webpack.DefinePlugin(env.stringified),
|
496
|
-
new MiniCssExtractPlugin({
|
497
|
-
// Options similar to the same options in webpackOptions.output
|
498
|
-
// both options are optional
|
499
|
-
filename: cssFilename,
|
500
|
-
chunkFilename: cssChunkFilename,
|
501
|
-
}),
|
502
|
-
// Generate a manifest file which contains a mapping of all asset filenames
|
503
|
-
// to their corresponding output file so that tools can pick it up without
|
504
|
-
// having to parse `index.html`.
|
505
|
-
new ManifestPlugin({
|
506
|
-
fileName: 'asset-manifest.json',
|
507
|
-
publicPath,
|
508
|
-
}),
|
509
|
-
// Moment.js is an extremely popular library that bundles large locale files
|
510
|
-
// by default due to how Webpack interprets its code. This is a practical
|
511
|
-
// solution that requires the user to opt into importing specific locales.
|
512
|
-
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
513
|
-
// You can remove this if you don't use Moment.js:
|
514
|
-
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
515
|
-
// Ignore react-intl locale except fr and en
|
516
|
-
new webpack.IgnorePlugin(/(?!fr|en)([a-z]{2,3})/, /locale-data/),
|
517
|
-
// Generate a service worker script that will precache, and keep up to date,
|
518
|
-
// the HTML & assets that are part of the Webpack build.
|
519
|
-
new WorkboxWebpackPlugin.GenerateSW({
|
520
|
-
clientsClaim: true,
|
521
|
-
exclude: [/\.map$/, /asset-manifest\.json$/],
|
522
|
-
importWorkboxFrom: 'cdn',
|
523
|
-
...(hasHtml ? {
|
524
|
-
navigateFallback: `${publicUrl}/index.html`,
|
525
|
-
navigateFallbackBlacklist: [
|
526
|
-
// Exclude URLs starting with /_, as they're likely an API call
|
527
|
-
new RegExp('^/_'),
|
528
|
-
// Exclude URLs containing a dot, as they're likely a resource in
|
529
|
-
// public/ and not a SPA route
|
530
|
-
new RegExp('/[^/]+\\.[^/]+$'),
|
531
|
-
],
|
532
|
-
} : null),
|
533
|
-
runtimeCaching: [
|
534
|
-
{
|
535
|
-
urlPattern: /^https:\/\/fonts\.googleapis\.com\//,
|
536
|
-
handler: 'cacheFirst',
|
537
|
-
},
|
538
|
-
{
|
539
|
-
urlPattern: /^https:\/\/cdn\.polyfill\.io\//,
|
540
|
-
handler: 'cacheFirst',
|
541
|
-
},
|
542
|
-
...(!hasHtml ? [
|
543
|
-
{
|
544
|
-
urlPattern: /\/(fr|en)(\.json)?$/,
|
545
|
-
handler: 'networkFirst',
|
546
|
-
},
|
547
|
-
{
|
548
|
-
urlPattern: /\/(fr|en)\/(.*)$/,
|
549
|
-
handler: 'networkFirst',
|
550
|
-
},
|
551
|
-
{
|
552
|
-
urlPattern: /\/files\/(.*)$/,
|
553
|
-
handler: 'cacheFirst',
|
554
|
-
},
|
555
|
-
] : []),
|
556
|
-
],
|
557
|
-
}),
|
558
|
-
],
|
559
|
-
// Some libraries import Node modules but don't use them in the browser.
|
560
|
-
// Tell Webpack to provide empty mocks for them so importing them works.
|
561
|
-
node: {
|
562
|
-
dgram: 'empty',
|
563
|
-
fs: 'empty',
|
564
|
-
net: 'empty',
|
565
|
-
tls: 'empty',
|
566
|
-
child_process: 'empty',
|
567
|
-
},
|
568
|
-
// Turn off performance processing because we utilize
|
569
|
-
// our own hints via the FileSizeReporter
|
570
|
-
performance: false,
|
571
|
-
};
|