|
@@ -1,75 +1,70 @@
|
|
|
+const fs = require('fs')
|
|
|
+const path = require('path')
|
|
|
+const webpack = require('webpack')
|
|
|
+const resolve = require('resolve')
|
|
|
+const PnpWebpackPlugin = require('pnp-webpack-plugin')
|
|
|
+const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
|
+const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
|
|
|
+const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin')
|
|
|
+const TerserPlugin = require('terser-webpack-plugin')
|
|
|
+const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
|
+const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
|
|
+const safePostCssParser = require('postcss-safe-parser')
|
|
|
+const ManifestPlugin = require('webpack-manifest-plugin')
|
|
|
+const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin')
|
|
|
+const WorkboxWebpackPlugin = require('workbox-webpack-plugin')
|
|
|
+const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin')
|
|
|
+const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin')
|
|
|
+const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent')
|
|
|
+const paths = require('./paths')
|
|
|
+const modules = require('./modules')
|
|
|
+const getClientEnvironment = require('./env')
|
|
|
+const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin')
|
|
|
+const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin')
|
|
|
+const typescriptFormatter = require('react-dev-utils/typescriptFormatter')
|
|
|
+const CompressionPlugin = require('compression-webpack-plugin')
|
|
|
|
|
|
+const postcssNormalize = require('postcss-normalize')
|
|
|
|
|
|
-const fs = require('fs');
|
|
|
-const path = require('path');
|
|
|
-const webpack = require('webpack');
|
|
|
-const resolve = require('resolve');
|
|
|
-const PnpWebpackPlugin = require('pnp-webpack-plugin');
|
|
|
-const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
-const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
|
|
-const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
|
|
|
-const TerserPlugin = require('terser-webpack-plugin');
|
|
|
-const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
-const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
|
|
-const safePostCssParser = require('postcss-safe-parser');
|
|
|
-const ManifestPlugin = require('webpack-manifest-plugin');
|
|
|
-const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
|
|
-const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
|
|
|
-const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
|
|
-const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
|
|
-const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
|
|
|
-const paths = require('./paths');
|
|
|
-const modules = require('./modules');
|
|
|
-const getClientEnvironment = require('./env');
|
|
|
-const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
|
|
|
-const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
|
|
|
-const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
|
|
|
-const CompressionPlugin = require('compression-webpack-plugin');
|
|
|
-
|
|
|
-const postcssNormalize = require('postcss-normalize');
|
|
|
-
|
|
|
-const appPackageJson = require(paths.appPackageJson);
|
|
|
+const appPackageJson = require(paths.appPackageJson)
|
|
|
|
|
|
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
|
|
// const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
|
|
-const shouldUseSourceMap = false;
|
|
|
+const shouldUseSourceMap = false
|
|
|
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
|
|
|
// makes for a smoother build process.
|
|
|
-const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
|
|
|
+const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false'
|
|
|
|
|
|
-const isExtendingEslintConfig = process.env.EXTEND_ESLINT === 'true';
|
|
|
+const isExtendingEslintConfig = process.env.EXTEND_ESLINT === 'true'
|
|
|
|
|
|
-const imageInlineSizeLimit = parseInt(
|
|
|
- process.env.IMAGE_INLINE_SIZE_LIMIT || '10000'
|
|
|
-);
|
|
|
+const imageInlineSizeLimit = parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT || '10000')
|
|
|
|
|
|
// Check if TypeScript is setup
|
|
|
-const useTypeScript = fs.existsSync(paths.appTsConfig);
|
|
|
+const useTypeScript = fs.existsSync(paths.appTsConfig)
|
|
|
|
|
|
// style files regexes
|
|
|
-const cssRegex = /\.css$/;
|
|
|
-const cssModuleRegex = /\.module\.css$/;
|
|
|
-const sassRegex = /\.(scss|sass)$/;
|
|
|
-const sassModuleRegex = /\.module\.(scss|sass)$/;
|
|
|
-const lessRegex = /\.less$/;
|
|
|
-const lessModuleRegex = /\.module\.less$/;
|
|
|
+const cssRegex = /\.css$/
|
|
|
+const cssModuleRegex = /\.module\.css$/
|
|
|
+const sassRegex = /\.(scss|sass)$/
|
|
|
+const sassModuleRegex = /\.module\.(scss|sass)$/
|
|
|
+const lessRegex = /\.less$/
|
|
|
+const lessModuleRegex = /\.module\.less$/
|
|
|
|
|
|
// This is the production and development configuration.
|
|
|
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
|
-module.exports = function(webpackEnv) {
|
|
|
- const isEnvDevelopment = webpackEnv === 'development';
|
|
|
- const isEnvProduction = webpackEnv === 'production';
|
|
|
+module.exports = function (webpackEnv) {
|
|
|
+ const isEnvDevelopment = webpackEnv === 'development'
|
|
|
+ const isEnvProduction = webpackEnv === 'production'
|
|
|
|
|
|
// Variable used for enabling profiling in Production
|
|
|
// passed into alias object. Uses a flag if passed into the build command
|
|
|
- const isEnvProductionProfile =
|
|
|
- isEnvProduction && process.argv.includes('--profile');
|
|
|
+ const isEnvProductionProfile = isEnvProduction && process.argv.includes('--profile')
|
|
|
|
|
|
// We will provide `paths.publicUrlOrPath` to our app
|
|
|
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
|
|
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
|
|
// Get environment variables to inject into our app.
|
|
|
- const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
|
|
|
+ const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1))
|
|
|
|
|
|
// common function to get style loaders
|
|
|
const getStyleLoaders = (cssOptions, preProcessor) => {
|
|
@@ -79,13 +74,11 @@ module.exports = function(webpackEnv) {
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
// css is located in `static/css`, use '../../' to locate index.html folder
|
|
|
// in production `paths.publicUrlOrPath` can be a relative path
|
|
|
- options: paths.publicUrlOrPath.startsWith('.')
|
|
|
- ? { publicPath: '../../' }
|
|
|
- : {},
|
|
|
+ options: paths.publicUrlOrPath.startsWith('.') ? { publicPath: '../../' } : {}
|
|
|
},
|
|
|
{
|
|
|
loader: require.resolve('css-loader'),
|
|
|
- options: cssOptions,
|
|
|
+ options: cssOptions
|
|
|
},
|
|
|
{
|
|
|
// Options for PostCSS as we reference these options twice
|
|
@@ -100,19 +93,19 @@ module.exports = function(webpackEnv) {
|
|
|
require('postcss-flexbugs-fixes'),
|
|
|
require('postcss-preset-env')({
|
|
|
autoprefixer: {
|
|
|
- flexbox: 'no-2009',
|
|
|
+ flexbox: 'no-2009'
|
|
|
},
|
|
|
- stage: 3,
|
|
|
+ stage: 3
|
|
|
}),
|
|
|
// Adds PostCSS Normalize as the reset css with default options,
|
|
|
// so that it honors browserslist config in package.json
|
|
|
// which in turn let's users customize the target behavior as per their needs.
|
|
|
- postcssNormalize(),
|
|
|
+ postcssNormalize()
|
|
|
],
|
|
|
- sourceMap: isEnvProduction && shouldUseSourceMap,
|
|
|
- },
|
|
|
- },
|
|
|
- ].filter(Boolean);
|
|
|
+ sourceMap: isEnvProduction && shouldUseSourceMap
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ].filter(Boolean)
|
|
|
if (preProcessor) {
|
|
|
// loaders.push(
|
|
|
// {
|
|
@@ -129,31 +122,27 @@ module.exports = function(webpackEnv) {
|
|
|
// }
|
|
|
// );
|
|
|
let loader = require.resolve(preProcessor)
|
|
|
- if (preProcessor === "less-loader") {
|
|
|
+ if (preProcessor === 'less-loader') {
|
|
|
loader = {
|
|
|
loader,
|
|
|
options: {
|
|
|
lessOptions: {
|
|
|
modifyVars: { '@primary-color': '#007bff', '@font-size-base': '12px', '@border-radius-base': '.2rem' },
|
|
|
- javascriptEnabled: true,
|
|
|
- },
|
|
|
- },
|
|
|
+ javascriptEnabled: true
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- loaders.push(loader);
|
|
|
+ loaders.push(loader)
|
|
|
}
|
|
|
- return loaders;
|
|
|
- };
|
|
|
+ return loaders
|
|
|
+ }
|
|
|
|
|
|
return {
|
|
|
mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
|
|
|
// Stop compilation early in production
|
|
|
bail: isEnvProduction,
|
|
|
- devtool: isEnvProduction
|
|
|
- ? shouldUseSourceMap
|
|
|
- ? 'source-map'
|
|
|
- : false
|
|
|
- : isEnvDevelopment && 'cheap-module-source-map',
|
|
|
+ devtool: isEnvProduction ? (shouldUseSourceMap ? 'source-map' : false) : isEnvDevelopment && 'cheap-module-source-map',
|
|
|
// These are the "entry points" to our application.
|
|
|
// This means they will be the "root" imports that are included in JS bundle.
|
|
|
entry: [
|
|
@@ -167,10 +156,9 @@ module.exports = function(webpackEnv) {
|
|
|
// the line below with these two lines if you prefer the stock client:
|
|
|
// require.resolve('webpack-dev-server/client') + '?/',
|
|
|
// require.resolve('webpack/hot/dev-server'),
|
|
|
- isEnvDevelopment &&
|
|
|
- require.resolve('react-dev-utils/webpackHotDevClient'),
|
|
|
+ isEnvDevelopment && require.resolve('react-dev-utils/webpackHotDevClient'),
|
|
|
// Finally, this is your app's code:
|
|
|
- paths.appIndexJs,
|
|
|
+ paths.appIndexJs
|
|
|
// We include the app code last so that if there is a runtime error during
|
|
|
// initialization, it doesn't blow up the WebpackDevServer client, and
|
|
|
// changing JS code would still trigger a refresh.
|
|
@@ -182,33 +170,25 @@ module.exports = function(webpackEnv) {
|
|
|
pathinfo: isEnvDevelopment,
|
|
|
// There will be one main bundle, and one file per asynchronous chunk.
|
|
|
// In development, it does not produce real files.
|
|
|
- filename: isEnvProduction
|
|
|
- ? 'static/js/[name].[contenthash:8].js'
|
|
|
- : isEnvDevelopment && 'static/js/bundle.js',
|
|
|
+ filename: isEnvProduction ? 'static/js/[name].[contenthash:8].js' : isEnvDevelopment && 'static/js/bundle.js',
|
|
|
// TODO: remove this when upgrading to webpack 5
|
|
|
futureEmitAssets: true,
|
|
|
// There are also additional JS chunk files if you use code splitting.
|
|
|
- chunkFilename: isEnvProduction
|
|
|
- ? 'static/js/[name].[contenthash:8].chunk.js'
|
|
|
- : isEnvDevelopment && 'static/js/[name].chunk.js',
|
|
|
+ chunkFilename: isEnvProduction ? 'static/js/[name].[contenthash:8].chunk.js' : isEnvDevelopment && 'static/js/[name].chunk.js',
|
|
|
// webpack uses `publicPath` to determine where the app is being served from.
|
|
|
// It requires a trailing slash, or the file assets will get an incorrect path.
|
|
|
// We inferred the "public path" (such as / or /my-project) from homepage.
|
|
|
publicPath: paths.publicUrlOrPath,
|
|
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
|
|
devtoolModuleFilenameTemplate: isEnvProduction
|
|
|
- ? info =>
|
|
|
- path
|
|
|
- .relative(paths.appSrc, info.absoluteResourcePath)
|
|
|
- .replace(/\\/g, '/')
|
|
|
- : isEnvDevelopment &&
|
|
|
- (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
|
|
|
+ ? info => path.relative(paths.appSrc, info.absoluteResourcePath).replace(/\\/g, '/')
|
|
|
+ : isEnvDevelopment && (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
|
|
|
// Prevents conflicts when multiple webpack runtimes (from different apps)
|
|
|
// are used on the same page.
|
|
|
jsonpFunction: `webpackJsonp${appPackageJson.name}`,
|
|
|
// this defaults to 'window', but by setting it to 'this' then
|
|
|
// module chunks which are built will work in web workers as well.
|
|
|
- globalObject: 'this',
|
|
|
+ globalObject: 'this'
|
|
|
},
|
|
|
optimization: {
|
|
|
minimize: isEnvProduction,
|
|
@@ -222,7 +202,7 @@ module.exports = function(webpackEnv) {
|
|
|
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
|
|
// sections only apply transformations that are ecma 5 safe
|
|
|
// https://github.com/facebook/create-react-app/pull/4234
|
|
|
- ecma: 8,
|
|
|
+ ecma: 8
|
|
|
},
|
|
|
compress: {
|
|
|
ecma: 5,
|
|
@@ -241,7 +221,7 @@ module.exports = function(webpackEnv) {
|
|
|
drop_debugger: isEnvProduction
|
|
|
},
|
|
|
mangle: {
|
|
|
- safari10: true,
|
|
|
+ safari10: true
|
|
|
},
|
|
|
// Added for profiling in devtools
|
|
|
keep_classnames: isEnvProductionProfile,
|
|
@@ -251,12 +231,12 @@ module.exports = function(webpackEnv) {
|
|
|
comments: false,
|
|
|
// Turned on because emoji and regex is not minified properly using default
|
|
|
// https://github.com/facebook/create-react-app/issues/2488
|
|
|
- ascii_only: true,
|
|
|
- },
|
|
|
+ ascii_only: true
|
|
|
+ }
|
|
|
},
|
|
|
sourceMap: shouldUseSourceMap,
|
|
|
- parallel: true, //此处为新增配置
|
|
|
- extractComments: false,
|
|
|
+ parallel: true, //此处为新增配置
|
|
|
+ extractComments: false
|
|
|
}),
|
|
|
// This is only used in production mode
|
|
|
new OptimizeCSSAssetsPlugin({
|
|
@@ -269,46 +249,42 @@ module.exports = function(webpackEnv) {
|
|
|
inline: false,
|
|
|
// `annotation: true` appends the sourceMappingURL to the end of
|
|
|
// the css file, helping the browser find the sourcemap
|
|
|
- annotation: true,
|
|
|
+ annotation: true
|
|
|
}
|
|
|
- : false,
|
|
|
+ : false
|
|
|
},
|
|
|
cssProcessorPluginOptions: {
|
|
|
- preset: ['default', { minifyFontValues: { removeQuotes: false } }],
|
|
|
- },
|
|
|
- }),
|
|
|
+ preset: ['default', { minifyFontValues: { removeQuotes: false } }]
|
|
|
+ }
|
|
|
+ })
|
|
|
],
|
|
|
// Automatically split vendor and commons
|
|
|
// https://twitter.com/wSokra/status/969633336732905474
|
|
|
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
|
|
|
splitChunks: {
|
|
|
chunks: 'all',
|
|
|
- name: false,
|
|
|
+ name: false
|
|
|
},
|
|
|
// Keep the runtime chunk separated to enable long term caching
|
|
|
// https://twitter.com/wSokra/status/969679223278505985
|
|
|
// https://github.com/facebook/create-react-app/issues/5358
|
|
|
runtimeChunk: {
|
|
|
- name: entrypoint => `runtime-${entrypoint.name}`,
|
|
|
- },
|
|
|
+ name: entrypoint => `runtime-${entrypoint.name}`
|
|
|
+ }
|
|
|
},
|
|
|
resolve: {
|
|
|
// This allows you to set a fallback for where webpack should look for modules.
|
|
|
// We placed these paths second because we want `node_modules` to "win"
|
|
|
// if there are any conflicts. This matches Node resolution mechanism.
|
|
|
// https://github.com/facebook/create-react-app/issues/253
|
|
|
- modules: ['node_modules', paths.appNodeModules].concat(
|
|
|
- modules.additionalModulePaths || []
|
|
|
- ),
|
|
|
+ modules: ['node_modules', paths.appNodeModules].concat(modules.additionalModulePaths || []),
|
|
|
// These are the reasonable defaults supported by the Node ecosystem.
|
|
|
// We also include JSX as a common component filename extension to support
|
|
|
// some tools, although we do not recommend using it, see:
|
|
|
// https://github.com/facebook/create-react-app/issues/290
|
|
|
// `web` extension prefixes have been added for better support
|
|
|
// for React Native Web.
|
|
|
- extensions: paths.moduleFileExtensions
|
|
|
- .map(ext => `.${ext}`)
|
|
|
- .filter(ext => useTypeScript || !ext.includes('ts')),
|
|
|
+ extensions: paths.moduleFileExtensions.map(ext => `.${ext}`).filter(ext => useTypeScript || !ext.includes('ts')),
|
|
|
alias: {
|
|
|
// Support React Native Web
|
|
|
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
|
@@ -316,7 +292,7 @@ module.exports = function(webpackEnv) {
|
|
|
// Allows for better profiling with ReactDevTools
|
|
|
...(isEnvProductionProfile && {
|
|
|
'react-dom$': 'react-dom/profiling',
|
|
|
- 'scheduler/tracing': 'scheduler/tracing-profiling',
|
|
|
+ 'scheduler/tracing': 'scheduler/tracing-profiling'
|
|
|
}),
|
|
|
...(modules.webpackAliases || {}),
|
|
|
'@': paths.appSrc
|
|
@@ -331,15 +307,15 @@ module.exports = function(webpackEnv) {
|
|
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
|
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
|
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
|
|
- new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
|
|
- ],
|
|
|
+ new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson])
|
|
|
+ ]
|
|
|
},
|
|
|
resolveLoader: {
|
|
|
plugins: [
|
|
|
// Also related to Plug'n'Play, but this time it tells webpack to load its loaders
|
|
|
// from the current package.
|
|
|
- PnpWebpackPlugin.moduleLoader(module),
|
|
|
- ],
|
|
|
+ PnpWebpackPlugin.moduleLoader(module)
|
|
|
+ ]
|
|
|
},
|
|
|
module: {
|
|
|
strictExportPresence: true,
|
|
@@ -372,10 +348,10 @@ module.exports = function(webpackEnv) {
|
|
|
oneOf: [
|
|
|
{
|
|
|
test: /\.svg$/,
|
|
|
- loader: "svg-sprite-loader",
|
|
|
- include: path.resolve(__dirname, "../src/assets/icons"), //只处理指定svg的文件(所有使用的svg文件放到该文件夹下)
|
|
|
+ loader: 'svg-sprite-loader',
|
|
|
+ include: path.resolve(__dirname, '../src/assets/icons'), //只处理指定svg的文件(所有使用的svg文件放到该文件夹下)
|
|
|
options: {
|
|
|
- symbolId: "icon-[name]" //symbolId和use使用的名称对应 <use xlinkHref={"#icon-" + iconClass} />
|
|
|
+ symbolId: 'icon-[name]' //symbolId和use使用的名称对应 <use xlinkHref={"#icon-" + iconClass} />
|
|
|
}
|
|
|
},
|
|
|
// "url" loader works like "file" loader except that it embeds assets
|
|
@@ -386,8 +362,8 @@ module.exports = function(webpackEnv) {
|
|
|
loader: require.resolve('url-loader'),
|
|
|
options: {
|
|
|
limit: imageInlineSizeLimit,
|
|
|
- name: 'static/media/[name].[hash:8].[ext]',
|
|
|
- },
|
|
|
+ name: 'static/media/[name].[hash:8].[ext]'
|
|
|
+ }
|
|
|
},
|
|
|
// Process application JS with Babel.
|
|
|
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
|
|
@@ -396,9 +372,7 @@ module.exports = function(webpackEnv) {
|
|
|
include: paths.appSrc,
|
|
|
loader: require.resolve('babel-loader'),
|
|
|
options: {
|
|
|
- customize: require.resolve(
|
|
|
- 'babel-preset-react-app/webpack-overrides'
|
|
|
- ),
|
|
|
+ customize: require.resolve('babel-preset-react-app/webpack-overrides'),
|
|
|
|
|
|
plugins: [
|
|
|
[
|
|
@@ -406,11 +380,10 @@ module.exports = function(webpackEnv) {
|
|
|
{
|
|
|
loaderMap: {
|
|
|
svg: {
|
|
|
- ReactComponent:
|
|
|
- '@svgr/webpack?-svgo,+titleProp,+ref![path]',
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
+ ReactComponent: '@svgr/webpack?-svgo,+titleProp,+ref![path]'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
]
|
|
|
],
|
|
|
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
|
@@ -419,8 +392,8 @@ module.exports = function(webpackEnv) {
|
|
|
cacheDirectory: true,
|
|
|
// See #6846 for context on why cacheCompression is disabled
|
|
|
cacheCompression: false,
|
|
|
- compact: isEnvProduction,
|
|
|
- },
|
|
|
+ compact: isEnvProduction
|
|
|
+ }
|
|
|
},
|
|
|
// Process any JS outside of the app with Babel.
|
|
|
// Unlike the application JS, we only compile the standard ES features.
|
|
@@ -432,12 +405,7 @@ module.exports = function(webpackEnv) {
|
|
|
babelrc: false,
|
|
|
configFile: false,
|
|
|
compact: false,
|
|
|
- presets: [
|
|
|
- [
|
|
|
- require.resolve('babel-preset-react-app/dependencies'),
|
|
|
- { helpers: true },
|
|
|
- ],
|
|
|
- ],
|
|
|
+ presets: [[require.resolve('babel-preset-react-app/dependencies'), { helpers: true }]],
|
|
|
cacheDirectory: true,
|
|
|
// See #6846 for context on why cacheCompression is disabled
|
|
|
cacheCompression: false,
|
|
@@ -446,8 +414,8 @@ module.exports = function(webpackEnv) {
|
|
|
// code. Without the options below, debuggers like VSCode
|
|
|
// show incorrect code and set breakpoints on the wrong lines.
|
|
|
sourceMaps: shouldUseSourceMap,
|
|
|
- inputSourceMap: shouldUseSourceMap,
|
|
|
- },
|
|
|
+ inputSourceMap: shouldUseSourceMap
|
|
|
+ }
|
|
|
},
|
|
|
// "postcss" loader applies autoprefixer to our CSS.
|
|
|
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
|
@@ -461,13 +429,13 @@ module.exports = function(webpackEnv) {
|
|
|
exclude: cssModuleRegex,
|
|
|
use: getStyleLoaders({
|
|
|
importLoaders: 1,
|
|
|
- sourceMap: isEnvProduction && shouldUseSourceMap,
|
|
|
+ sourceMap: isEnvProduction && shouldUseSourceMap
|
|
|
}),
|
|
|
// Don't consider CSS imports dead code even if the
|
|
|
// containing package claims to have no side effects.
|
|
|
// Remove this when webpack adds a warning or an error for this.
|
|
|
// See https://github.com/webpack/webpack/issues/6571
|
|
|
- sideEffects: true,
|
|
|
+ sideEffects: true
|
|
|
},
|
|
|
// Adds support for CSS Modules (https://github.com/css-modules/css-modules)
|
|
|
// using the extension .module.css
|
|
@@ -477,9 +445,9 @@ module.exports = function(webpackEnv) {
|
|
|
importLoaders: 1,
|
|
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
|
|
modules: {
|
|
|
- getLocalIdent: getCSSModuleLocalIdent,
|
|
|
- },
|
|
|
- }),
|
|
|
+ getLocalIdent: getCSSModuleLocalIdent
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
// Opt-in support for SASS (using .scss or .sass extensions).
|
|
|
// By default we support SASS Modules with the
|
|
@@ -490,7 +458,7 @@ module.exports = function(webpackEnv) {
|
|
|
use: getStyleLoaders(
|
|
|
{
|
|
|
importLoaders: 3,
|
|
|
- sourceMap: isEnvProduction && shouldUseSourceMap,
|
|
|
+ sourceMap: isEnvProduction && shouldUseSourceMap
|
|
|
},
|
|
|
'sass-loader'
|
|
|
),
|
|
@@ -498,7 +466,7 @@ module.exports = function(webpackEnv) {
|
|
|
// containing package claims to have no side effects.
|
|
|
// Remove this when webpack adds a warning or an error for this.
|
|
|
// See https://github.com/webpack/webpack/issues/6571
|
|
|
- sideEffects: true,
|
|
|
+ sideEffects: true
|
|
|
},
|
|
|
// Adds support for CSS Modules, but using SASS
|
|
|
// using the extension .module.scss or .module.sass
|
|
@@ -509,11 +477,11 @@ module.exports = function(webpackEnv) {
|
|
|
importLoaders: 3,
|
|
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
|
|
modules: {
|
|
|
- getLocalIdent: getCSSModuleLocalIdent,
|
|
|
- },
|
|
|
+ getLocalIdent: getCSSModuleLocalIdent
|
|
|
+ }
|
|
|
},
|
|
|
'sass-loader'
|
|
|
- ),
|
|
|
+ )
|
|
|
},
|
|
|
// Opt-in support for SASS (using .scss or .sass extensions).
|
|
|
// By default we support SASS Modules with the
|
|
@@ -523,7 +491,7 @@ module.exports = function(webpackEnv) {
|
|
|
exclude: lessModuleRegex,
|
|
|
use: getStyleLoaders(
|
|
|
{
|
|
|
- importLoaders: 2,
|
|
|
+ importLoaders: 2
|
|
|
},
|
|
|
'less-loader'
|
|
|
)
|
|
@@ -533,13 +501,13 @@ module.exports = function(webpackEnv) {
|
|
|
{
|
|
|
test: lessModuleRegex,
|
|
|
use: getStyleLoaders(
|
|
|
- {
|
|
|
- importLoaders: 2,
|
|
|
- modules: true,
|
|
|
- getLocalIdent: getCSSModuleLocalIdent,
|
|
|
- },
|
|
|
- 'less-loader'
|
|
|
- ),
|
|
|
+ {
|
|
|
+ importLoaders: 2,
|
|
|
+ modules: true,
|
|
|
+ getLocalIdent: getCSSModuleLocalIdent
|
|
|
+ },
|
|
|
+ 'less-loader'
|
|
|
+ )
|
|
|
},
|
|
|
// "file" loader makes sure those assets get served by WebpackDevServer.
|
|
|
// When you `import` an asset, you get its (virtual) filename.
|
|
@@ -554,14 +522,14 @@ module.exports = function(webpackEnv) {
|
|
|
// by webpacks internal loaders.
|
|
|
exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
|
|
|
options: {
|
|
|
- name: 'static/media/[name].[hash:8].[ext]',
|
|
|
- },
|
|
|
- },
|
|
|
+ name: 'static/media/[name].[hash:8].[ext]'
|
|
|
+ }
|
|
|
+ }
|
|
|
// ** STOP ** Are you adding a new loader?
|
|
|
// Make sure to add the new loader(s) before the "file" loader.
|
|
|
- ],
|
|
|
- },
|
|
|
- ],
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
},
|
|
|
plugins: [
|
|
|
// Generates an `index.html` file with the <script> injected.
|
|
@@ -570,7 +538,7 @@ module.exports = function(webpackEnv) {
|
|
|
{},
|
|
|
{
|
|
|
inject: true,
|
|
|
- template: paths.appHtml,
|
|
|
+ template: paths.appHtml
|
|
|
},
|
|
|
isEnvProduction
|
|
|
? {
|
|
@@ -584,8 +552,8 @@ module.exports = function(webpackEnv) {
|
|
|
keepClosingSlash: true,
|
|
|
minifyJS: true,
|
|
|
minifyCSS: true,
|
|
|
- minifyURLs: true,
|
|
|
- },
|
|
|
+ minifyURLs: true
|
|
|
+ }
|
|
|
}
|
|
|
: undefined
|
|
|
)
|
|
@@ -593,9 +561,7 @@ module.exports = function(webpackEnv) {
|
|
|
// Inlines the webpack runtime script. This script is too small to warrant
|
|
|
// a network request.
|
|
|
// https://github.com/facebook/create-react-app/issues/5358
|
|
|
- isEnvProduction &&
|
|
|
- shouldInlineRuntimeChunk &&
|
|
|
- new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime-.+[.]js/]),
|
|
|
+ isEnvProduction && shouldInlineRuntimeChunk && new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime-.+[.]js/]),
|
|
|
// Makes some environment variables available in index.html.
|
|
|
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
|
|
// <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
|
|
@@ -621,14 +587,13 @@ module.exports = function(webpackEnv) {
|
|
|
// to restart the development server for webpack to discover it. This plugin
|
|
|
// makes the discovery automatic so you don't have to restart.
|
|
|
// See https://github.com/facebook/create-react-app/issues/186
|
|
|
- isEnvDevelopment &&
|
|
|
- new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
|
|
+ isEnvDevelopment && new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
|
|
isEnvProduction &&
|
|
|
new MiniCssExtractPlugin({
|
|
|
// Options similar to the same options in webpackOptions.output
|
|
|
// both options are optional
|
|
|
filename: 'static/css/[name].[contenthash:8].css',
|
|
|
- chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
|
|
|
+ chunkFilename: 'static/css/[name].[contenthash:8].chunk.css'
|
|
|
}),
|
|
|
// Generate an asset manifest file with the following content:
|
|
|
// - "files" key: Mapping of all asset filenames to their corresponding
|
|
@@ -641,18 +606,16 @@ module.exports = function(webpackEnv) {
|
|
|
publicPath: paths.publicUrlOrPath,
|
|
|
generate: (seed, files, entrypoints) => {
|
|
|
const manifestFiles = files.reduce((manifest, file) => {
|
|
|
- manifest[file.name] = file.path;
|
|
|
- return manifest;
|
|
|
- }, seed);
|
|
|
- const entrypointFiles = entrypoints.main.filter(
|
|
|
- fileName => !fileName.endsWith('.map')
|
|
|
- );
|
|
|
+ manifest[file.name] = file.path
|
|
|
+ return manifest
|
|
|
+ }, seed)
|
|
|
+ const entrypointFiles = entrypoints.main.filter(fileName => !fileName.endsWith('.map'))
|
|
|
|
|
|
return {
|
|
|
files: manifestFiles,
|
|
|
- entrypoints: entrypointFiles,
|
|
|
- };
|
|
|
- },
|
|
|
+ entrypoints: entrypointFiles
|
|
|
+ }
|
|
|
+ }
|
|
|
}),
|
|
|
// Moment.js is an extremely popular library that bundles large locale files
|
|
|
// by default due to how webpack interprets its code. This is a practical
|
|
@@ -675,43 +638,44 @@ module.exports = function(webpackEnv) {
|
|
|
// as they're likely a resource and not a SPA route.
|
|
|
// URLs containing a "?" character won't be blacklisted as they're likely
|
|
|
// a route with query params (e.g. auth callbacks).
|
|
|
- new RegExp('/[^/?]+\\.[^/]+$'),
|
|
|
- ],
|
|
|
- }),
|
|
|
- isEnvProduction && new CompressionPlugin({
|
|
|
- filename: '[path][base].gz[query]',
|
|
|
- algorithm: 'gzip',
|
|
|
- test: /\.(css|js)$/,
|
|
|
- threshold: 10240,
|
|
|
- minRatio: 0.8
|
|
|
- }),
|
|
|
- // TypeScript type checking
|
|
|
- useTypeScript &&
|
|
|
- new ForkTsCheckerWebpackPlugin({
|
|
|
- typescript: resolve.sync('typescript', {
|
|
|
- basedir: paths.appNodeModules,
|
|
|
- }),
|
|
|
- async: isEnvDevelopment,
|
|
|
- useTypescriptIncrementalApi: true,
|
|
|
- checkSyntacticErrors: true,
|
|
|
- resolveModuleNameModule: process.versions.pnp
|
|
|
- ? `${__dirname}/pnpTs.js`
|
|
|
- : undefined,
|
|
|
- resolveTypeReferenceDirectiveModule: process.versions.pnp
|
|
|
- ? `${__dirname}/pnpTs.js`
|
|
|
- : undefined,
|
|
|
- tsconfig: paths.appTsConfig,
|
|
|
- reportFiles: [
|
|
|
- '**',
|
|
|
- '!**/__tests__/**',
|
|
|
- '!**/?(*.)(spec|test).*',
|
|
|
- '!**/src/setupProxy.*',
|
|
|
- '!**/src/setupTests.*',
|
|
|
- ],
|
|
|
- silent: true,
|
|
|
- // The formatter is invoked directly in WebpackDevServerUtils during development
|
|
|
- formatter: isEnvProduction ? typescriptFormatter : undefined,
|
|
|
+ new RegExp('/[^/?]+\\.[^/]+$')
|
|
|
+ ]
|
|
|
}),
|
|
|
+ isEnvProduction &&
|
|
|
+ new CompressionPlugin({
|
|
|
+ filename: '[path][base].gz[query]',
|
|
|
+ algorithm: 'gzip',
|
|
|
+ test: /\.(css|js)$/,
|
|
|
+ threshold: 10240,
|
|
|
+ minRatio: 0.8
|
|
|
+ })
|
|
|
+ // // TypeScript type checking
|
|
|
+ // useTypeScript &&
|
|
|
+ // new ForkTsCheckerWebpackPlugin({
|
|
|
+ // typescript: resolve.sync('typescript', {
|
|
|
+ // basedir: paths.appNodeModules,
|
|
|
+ // }),
|
|
|
+ // async: isEnvDevelopment,
|
|
|
+ // useTypescriptIncrementalApi: true,
|
|
|
+ // checkSyntacticErrors: true,
|
|
|
+ // resolveModuleNameModule: process.versions.pnp
|
|
|
+ // ? `${__dirname}/pnpTs.js`
|
|
|
+ // : undefined,
|
|
|
+ // resolveTypeReferenceDirectiveModule: process.versions.pnp
|
|
|
+ // ? `${__dirname}/pnpTs.js`
|
|
|
+ // : undefined,
|
|
|
+ // tsconfig: paths.appTsConfig,
|
|
|
+ // reportFiles: [
|
|
|
+ // '**',
|
|
|
+ // '!**/__tests__/**',
|
|
|
+ // '!**/?(*.)(spec|test).*',
|
|
|
+ // '!**/src/setupProxy.*',
|
|
|
+ // '!**/src/setupTests.*',
|
|
|
+ // ],
|
|
|
+ // silent: true,
|
|
|
+ // // The formatter is invoked directly in WebpackDevServerUtils during development
|
|
|
+ // formatter: isEnvProduction ? typescriptFormatter : undefined,
|
|
|
+ // }),
|
|
|
].filter(Boolean),
|
|
|
// Some libraries import Node modules but don't use them in the browser.
|
|
|
// Tell webpack to provide empty mocks for them so importing them works.
|
|
@@ -723,10 +687,10 @@ module.exports = function(webpackEnv) {
|
|
|
http2: 'empty',
|
|
|
net: 'empty',
|
|
|
tls: 'empty',
|
|
|
- child_process: 'empty',
|
|
|
+ child_process: 'empty'
|
|
|
},
|
|
|
// Turn off performance processing because we utilize
|
|
|
// our own hints via the FileSizeReporter
|
|
|
- performance: false,
|
|
|
- };
|
|
|
-};
|
|
|
+ performance: false
|
|
|
+ }
|
|
|
+}
|