diff --git a/babel.config.js b/babel.config.js index 83ee92ff0..4b17e0adb 100644 --- a/babel.config.js +++ b/babel.config.js @@ -3,7 +3,7 @@ const plugins = [ ['@babel/plugin-proposal-decorators', { legacy: true }], ['@babel/plugin-transform-runtime'], ['@babel/plugin-transform-modules-commonjs'], - ['@babel/plugin-proposal-object-rest-spread'], + ['@babel/plugin-proposal-object-rest-spread'] ] module.exports = { @@ -12,20 +12,20 @@ module.exports = { '@babel/preset-env', { targets: { - browsers: ['> 1%', 'last 2 versions', 'not ie <= 8'], + browsers: ['> 1%', 'last 2 versions', 'not ie <= 8'] }, modules: false, useBuiltIns: 'entry', - corejs: 3, - }, + corejs: 3 + } ], [ '@babel/preset-react', { - runtime: 'automatic', - }, + runtime: 'automatic' + } ], - '@babel/preset-typescript', + '@babel/preset-typescript' ], compact: true, comments: true, @@ -35,7 +35,7 @@ module.exports = { : plugins, env: { development: { - plugins: ['react-refresh/babel'], - }, - }, + plugins: ['react-refresh/babel'] + } + } } diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 11f4be780..ddb3f012c 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -37,7 +37,7 @@ switch (process.env.BUILD_GOAL) { const config = { entry: { - app: `${paths.src}/index.tsx`, + app: `${paths.src}/index.tsx` }, output: { path: paths.build, @@ -47,7 +47,7 @@ const config = { // library: '', // libraryTarget: 'umd', // chunkLoadingGlobal: '', - clean: true, + clean: true // contentBase: path.join(__dirname, "public"), // 配置额外的静态文件内容的访问路径 }, resolve: { @@ -62,17 +62,17 @@ const config = { '@pages': path.resolve('./src/pages'), '@routers': path.resolve('./src/routers'), '@utils': path.resolve('./src/utils'), - '@theme': path.resolve('./src/theme'), + '@theme': path.resolve('./src/theme') }, - symlinks: false, + symlinks: false }, stats: 'verbose', // 输出详细的构建信息 plugins: [ new Dotenv({ - path: path.resolve(__dirname, '..', dotEnv), + path: path.resolve(__dirname, '..', dotEnv) }), codeInspectorPlugin({ - bundler: 'webpack', + bundler: 'webpack' }), new HtmlWebpackPlugin({ title: isDev ? 'Pro React Dev' : 'Pro React Admin', @@ -96,8 +96,8 @@ const config = { minifyCSS: true, minifyJS: true, minifyURLs: true, - useShortDoctype: true, - }, + useShortDoctype: true + } }), new AntdDayjsWebpackPlugin(), new CaseSensitivePathsPlugin(), @@ -111,7 +111,7 @@ const config = { new NodePolyfillPlugin(), new WebpackBar(), new ForkTsCheckerWebpackPlugin({ - async: true, + async: true }), new ESLintWebpackPlugin({ // 指定检查文件的根目录 @@ -119,8 +119,8 @@ const config = { exclude: 'node_modules', // 默认值 cache: true, // 开启缓存 // 缓存目录 - cacheLocation: path.resolve(__dirname, '../node_modules/.cache/.eslintcache'), - }), + cacheLocation: path.resolve(__dirname, '../node_modules/.cache/.eslintcache') + }) ], module: { // 将缺失的导出提示成错误而不是警告 @@ -129,12 +129,12 @@ const config = { { test: /\.m?js$/, resolve: { - fullySpecified: false, - }, + fullySpecified: false + } }, { test: /\.css$/, - use: ['style-loader', 'css-loader', 'postcss-loader'], + use: ['style-loader', 'css-loader', 'postcss-loader'] }, { test: /\.less$/i, @@ -151,10 +151,10 @@ const config = { localIdentName: isDev ? '[path][name]__[local]--[hash:base64:5]' : '[local]--[hash:base64:5]', localIdentContext: paths.src, namedExport: false, - exportLocalsConvention: 'camelCase', + exportLocalsConvention: 'camelCase' }, - importLoaders: 2, - }, + importLoaders: 2 + } }, { loader: require.resolve('postcss-loader'), @@ -168,18 +168,18 @@ const config = { 'postcss-preset-env', { autoprefixer: { - flexbox: 'no-2009', + flexbox: 'no-2009' }, - stage: 3, - }, + stage: 3 + } ], - 'postcss-normalize', - ], + 'postcss-normalize' + ] }, - sourceMap: true, - }, - }, - ], + sourceMap: true + } + } + ] }, { test: /\.(js|jsx|ts|tsx)$/, @@ -189,17 +189,17 @@ const config = { loader: 'esbuild-loader', options: { // loader: 'tsx', - target: 'es2020', - }, + target: 'es2020' + } }, { loader: 'babel-loader', options: { presets: ['@babel/preset-env', '@babel/preset-react'], - plugins: ['@babel/plugin-transform-object-rest-spread', '@babel/plugin-transform-runtime'], - }, - }, - ], + plugins: ['@babel/plugin-transform-object-rest-spread', '@babel/plugin-transform-runtime'] + } + } + ] }, { test: /\.(png|jpe?g|gif|webp|eot|ttf|woff|woff2|mp4|mp3|mkv|pdf)$/i, @@ -207,29 +207,29 @@ const config = { parser: { // Conditions for converting to base64 dataUrlCondition: { - maxSize: 25 * 1024, // 25kb - }, + maxSize: 25 * 1024 // 25kb + } }, generator: { - filename: 'images/[contenthash][ext][query]', - }, + filename: 'images/[contenthash][ext][query]' + } }, { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, use: [ { - loader: 'babel-loader', + loader: 'babel-loader' }, { loader: '@svgr/webpack', options: { babel: false, - icon: true, - }, - }, - ], - }, - ], + icon: true + } + } + ] + } + ] }, stats: { all: false, @@ -237,14 +237,14 @@ const config = { warnings: true, errorDetails: true, moduleTrace: true, // 打印模块追踪信息,与--trace - warnings类似 - excludeAssets: /node_modules/, + excludeAssets: /node_modules/ }, // 性能提示 performance: { hints: isDev ? false : 'warning', maxEntrypointSize: 512000, - maxAssetSize: 512000, - }, + maxAssetSize: 512000 + } } if (USE_ANALYZE) { diff --git a/webpack/webpack.dev.js b/webpack/webpack.dev.js index 1f4f6da45..3d716c890 100644 --- a/webpack/webpack.dev.js +++ b/webpack/webpack.dev.js @@ -19,16 +19,16 @@ const devWebpackConfig = merge(common, { progress: true, overlay: { errors: true, - warnings: false, - }, + warnings: false + } }, static: { - directory: path.join(__dirname, '../public'), + directory: path.join(__dirname, '../public') }, compress: true, // open: true, hot: true, - proxy: devProxy, + proxy: devProxy }, // watch: true, // watchOptions: { @@ -46,17 +46,17 @@ const devWebpackConfig = merge(common, { loader: 'babel-loader', options: { presets: ['@babel/preset-env'], - plugins: [require.resolve('react-refresh/babel')].filter(Boolean), - }, - }, - ], - }, - ], + plugins: [require.resolve('react-refresh/babel')].filter(Boolean) + } + } + ] + } + ] }, plugins: [ new ReactRefreshWebpackPlugin({ - overlay: false, - }), + overlay: false + }) // new webpack.debug.ProfilingPlugin({ // outputPath: path.join(__dirname, 'profiling/profileEvents.json'), // }), @@ -71,20 +71,20 @@ const devWebpackConfig = merge(common, { test: /[\\/]node_modules[\\/]/, name: 'vendors', chunks: 'all', - priority: 10, - }, - }, + priority: 10 + } + } }, minimize: false, concatenateModules: false, - usedExports: false, - }, + usedExports: false + } }) module.exports = new Promise((resolve, reject) => { portfinder.getPort( { port: 8080, // 默认8080端口,若被占用,重复+1,直到找到可用端口或到stopPort才停止 - stopPort: 65535, // maximum port + stopPort: 65535 // maximum port }, (err, port) => { if (err) { diff --git a/webpack/webpack.prod.js b/webpack/webpack.prod.js index 9747e7a55..6c0fc1be6 100644 --- a/webpack/webpack.prod.js +++ b/webpack/webpack.prod.js @@ -31,14 +31,14 @@ const prodWebpackConfig = merge(common, { new MiniCssExtractPlugin({ filename: 'static/css/[name].[contenthash].css', chunkFilename: 'static/css/[name].[contenthash].css', - ignoreOrder: true, + ignoreOrder: true }), new PurgeCSSPlugin({ paths: glob.sync(`${path.join(__dirname, 'src')}/**/*`, { nodir: true }), only: ['bundle', 'vendor', 'dist'], safelist: { - standard: [/^ant-/], - }, + standard: [/^ant-/] + } }), // new CompressionWebpackPlugin({ // filename: '[path][base].gz', @@ -54,11 +54,11 @@ const prodWebpackConfig = merge(common, { from: path.resolve(__dirname, '../public'), to: path.resolve(__dirname, '../dist'), globOptions: { - ignore: ['**/index.html'], - }, - }, - ], - }), + ignore: ['**/index.html'] + } + } + ] + }) ], optimization: { minimize: true, @@ -75,9 +75,9 @@ const prodWebpackConfig = merge(common, { // }, // }), new EsbuildPlugin({ - target: 'es2015', + target: 'es2015' }), - new HtmlMinimizerPlugin(), + new HtmlMinimizerPlugin() ], splitChunks: { chunks: 'all', @@ -92,10 +92,10 @@ const prodWebpackConfig = merge(common, { minChunks: 1, priority: 10, enforce: true, - chunks: 'all', + chunks: 'all' }, react: { - test(module) { + test (module) { // `module.resource` contains the absolute path of the file on disk. return module.resource && module.resource.includes('node_modules/react') }, @@ -103,19 +103,19 @@ const prodWebpackConfig = merge(common, { filename: 'react.[contenthash].js', priority: 1, maxInitialRequests: 2, - minChunks: 1, - }, - }, + minChunks: 1 + } + } }, runtimeChunk: { - name: 'runtime', - }, + name: 'runtime' + } }, performance: { hints: false, maxEntrypointSize: 512000, - maxAssetSize: 512000, - }, + maxAssetSize: 512000 + } }) // if (useSentryMap) {