|
@@ -1,65 +1,62 @@
|
|
|
-'use strict';
|
|
|
+'use strict'
|
|
|
|
|
|
-const fs = require('fs');
|
|
|
-const isWsl = require('is-wsl');
|
|
|
-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 eslint = require('eslint');
|
|
|
+const fs = require('fs')
|
|
|
+const isWsl = require('is-wsl')
|
|
|
+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 eslint = require('eslint')
|
|
|
|
|
|
-const postcssNormalize = require('postcss-normalize');
|
|
|
+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 = process.env.GENERATE_SOURCEMAP !== '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 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 cssRegex = /\.css$/
|
|
|
+const cssModuleRegex = /\.module\.css$/
|
|
|
+const sassRegex = /\.(scss|sass)$/
|
|
|
+const sassModuleRegex = /\.module\.(scss|sass)$/
|
|
|
|
|
|
// 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')
|
|
|
|
|
|
// 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.
|
|
@@ -67,19 +64,17 @@ module.exports = function(webpackEnv) {
|
|
|
// const publicPath = isEnvProduction
|
|
|
// ? paths.servedPath
|
|
|
// : isEnvDevelopment && '/';
|
|
|
- const publicPath = './';
|
|
|
+ const publicPath = './'
|
|
|
// Some apps do not use client-side routing with pushState.
|
|
|
// For these, "homepage" can be set to "." to enable relative asset paths.
|
|
|
- const shouldUseRelativeAssetPaths = publicPath === './';
|
|
|
+ const shouldUseRelativeAssetPaths = publicPath === './'
|
|
|
|
|
|
// `publicUrl` is just like `publicPath`, but we will provide it 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.
|
|
|
- const publicUrl = isEnvProduction
|
|
|
- ? publicPath.slice(0, -1)
|
|
|
- : isEnvDevelopment && '';
|
|
|
+ const publicUrl = isEnvProduction ? publicPath.slice(0, -1) : isEnvDevelopment && ''
|
|
|
// Get environment variables to inject into our app.
|
|
|
- const env = getClientEnvironment(publicUrl);
|
|
|
+ const env = getClientEnvironment(publicUrl)
|
|
|
|
|
|
// common function to get style loaders
|
|
|
const getStyleLoaders = (cssOptions, preProcessor) => {
|
|
@@ -118,7 +113,7 @@ module.exports = function(webpackEnv) {
|
|
|
sourceMap: isEnvProduction && shouldUseSourceMap,
|
|
|
},
|
|
|
},
|
|
|
- ].filter(Boolean);
|
|
|
+ ].filter(Boolean)
|
|
|
if (preProcessor) {
|
|
|
loaders.push(
|
|
|
{
|
|
@@ -133,13 +128,24 @@ module.exports = function(webpackEnv) {
|
|
|
sourceMap: true,
|
|
|
},
|
|
|
}
|
|
|
- );
|
|
|
+ )
|
|
|
}
|
|
|
- return loaders;
|
|
|
- };
|
|
|
+ return loaders
|
|
|
+ }
|
|
|
|
|
|
return {
|
|
|
mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
|
|
|
+ devServer: {
|
|
|
+ logLevel: 'debug',
|
|
|
+ proxy: {
|
|
|
+ '/api': {
|
|
|
+ target: 'http://pengyi.w1.luyouxia.net/api/service-logan',
|
|
|
+ pathRewrite: { '^/api': '' },
|
|
|
+ changeOrigin: true,
|
|
|
+ secure: false,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
// Stop compilation early in production
|
|
|
bail: isEnvProduction,
|
|
|
devtool: isEnvProduction
|
|
@@ -160,8 +166,7 @@ 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,
|
|
|
// We include the app code last so that if there is a runtime error during
|
|
@@ -189,12 +194,9 @@ module.exports = function(webpackEnv) {
|
|
|
publicPath: publicPath,
|
|
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
|
|
devtoolModuleFilenameTemplate: isEnvProduction
|
|
|
- ? info =>
|
|
|
- path
|
|
|
- .relative(paths.appSrc, info.absoluteResourcePath)
|
|
|
- .replace(/\\/g, '/')
|
|
|
+ ? (info) => path.relative(paths.appSrc, info.absoluteResourcePath).replace(/\\/g, '/')
|
|
|
: isEnvDevelopment &&
|
|
|
- (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
|
|
|
+ ((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}`,
|
|
@@ -281,7 +283,7 @@ module.exports = function(webpackEnv) {
|
|
|
// 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: {
|
|
@@ -289,9 +291,7 @@ module.exports = function(webpackEnv) {
|
|
|
// 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:
|
|
@@ -299,8 +299,8 @@ module.exports = function(webpackEnv) {
|
|
|
// `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')),
|
|
|
+ .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/
|
|
@@ -349,7 +349,6 @@ module.exports = function(webpackEnv) {
|
|
|
formatter: require.resolve('react-dev-utils/eslintFormatter'),
|
|
|
eslintPath: require.resolve('eslint'),
|
|
|
resolvePluginsRelativeTo: __dirname,
|
|
|
-
|
|
|
},
|
|
|
loader: require.resolve('eslint-loader'),
|
|
|
},
|
|
@@ -379,18 +378,15 @@ 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: [
|
|
|
[
|
|
|
require.resolve('babel-plugin-named-asset-import'),
|
|
|
{
|
|
|
loaderMap: {
|
|
|
svg: {
|
|
|
- ReactComponent:
|
|
|
- '@svgr/webpack?-svgo,+titleProp,+ref![path]',
|
|
|
+ ReactComponent: '@svgr/webpack?-svgo,+titleProp,+ref![path]',
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -416,15 +412,12 @@ module.exports = function(webpackEnv) {
|
|
|
configFile: false,
|
|
|
compact: false,
|
|
|
presets: [
|
|
|
- [
|
|
|
- require.resolve('babel-preset-react-app/dependencies'),
|
|
|
- { helpers: true },
|
|
|
- ],
|
|
|
+ [require.resolve('babel-preset-react-app/dependencies'), { helpers: true }],
|
|
|
],
|
|
|
cacheDirectory: true,
|
|
|
// See #6846 for context on why cacheCompression is disabled
|
|
|
cacheCompression: false,
|
|
|
-
|
|
|
+
|
|
|
// If an error happens in a package, it's possible to be
|
|
|
// because it was compiled. Thus, we don't want the browser
|
|
|
// debugger to show the original code. Instead, the code
|
|
@@ -568,9 +561,9 @@ module.exports = function(webpackEnv) {
|
|
|
// Otherwise React will be compiled in the very slow development mode.
|
|
|
new webpack.DefinePlugin({
|
|
|
...env.stringified,
|
|
|
- "process.defineEnv": {
|
|
|
- API_BASE_URL: JSON.stringify(process.env.API_BASE_URL)
|
|
|
- }
|
|
|
+ 'process.defineEnv': {
|
|
|
+ API_BASE_URL: JSON.stringify(process.env.API_BASE_URL),
|
|
|
+ },
|
|
|
}),
|
|
|
// This is necessary to emit hot updates (currently CSS only):
|
|
|
isEnvDevelopment && new webpack.HotModuleReplacementPlugin(),
|
|
@@ -582,8 +575,7 @@ 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
|
|
@@ -602,17 +594,15 @@ module.exports = function(webpackEnv) {
|
|
|
publicPath: publicPath,
|
|
|
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,
|
|
|
- };
|
|
|
+ }
|
|
|
},
|
|
|
}),
|
|
|
// Moment.js is an extremely popular library that bundles large locale files
|
|
@@ -648,9 +638,7 @@ module.exports = function(webpackEnv) {
|
|
|
async: isEnvDevelopment,
|
|
|
useTypescriptIncrementalApi: true,
|
|
|
checkSyntacticErrors: true,
|
|
|
- resolveModuleNameModule: process.versions.pnp
|
|
|
- ? `${__dirname}/pnpTs.js`
|
|
|
- : undefined,
|
|
|
+ resolveModuleNameModule: process.versions.pnp ? `${__dirname}/pnpTs.js` : undefined,
|
|
|
resolveTypeReferenceDirectiveModule: process.versions.pnp
|
|
|
? `${__dirname}/pnpTs.js`
|
|
|
: undefined,
|
|
@@ -682,5 +670,5 @@ module.exports = function(webpackEnv) {
|
|
|
// Turn off performance processing because we utilize
|
|
|
// our own hints via the FileSizeReporter
|
|
|
performance: false,
|
|
|
- };
|
|
|
-};
|
|
|
+ }
|
|
|
+}
|