|
@@ -49,10 +49,12 @@ const cssRegex = /\.css$/;
|
|
const cssModuleRegex = /\.module\.css$/;
|
|
const cssModuleRegex = /\.module\.css$/;
|
|
const sassRegex = /\.(scss|sass)$/;
|
|
const sassRegex = /\.(scss|sass)$/;
|
|
const sassModuleRegex = /\.module\.(scss|sass)$/;
|
|
const sassModuleRegex = /\.module\.(scss|sass)$/;
|
|
-
|
|
|
|
|
|
+// 添加 less 解析规则
|
|
|
|
+const lessRegex = /\.less$/;
|
|
|
|
+const lessModuleRegex = /\.module\.less$/;
|
|
// This is the production and development configuration.
|
|
// This is the production and development configuration.
|
|
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
-module.exports = function(webpackEnv) {
|
|
|
|
|
|
+module.exports = function (webpackEnv) {
|
|
const isEnvDevelopment = webpackEnv === 'development';
|
|
const isEnvDevelopment = webpackEnv === 'development';
|
|
const isEnvProduction = webpackEnv === 'production';
|
|
const isEnvProduction = webpackEnv === 'production';
|
|
|
|
|
|
@@ -180,12 +182,13 @@ module.exports = function(webpackEnv) {
|
|
publicPath: paths.publicUrlOrPath,
|
|
publicPath: paths.publicUrlOrPath,
|
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
|
devtoolModuleFilenameTemplate: isEnvProduction
|
|
devtoolModuleFilenameTemplate: isEnvProduction
|
|
- ? info =>
|
|
|
|
|
|
+ ? (info) =>
|
|
path
|
|
path
|
|
.relative(paths.appSrc, info.absoluteResourcePath)
|
|
.relative(paths.appSrc, info.absoluteResourcePath)
|
|
.replace(/\\/g, '/')
|
|
.replace(/\\/g, '/')
|
|
: isEnvDevelopment &&
|
|
: isEnvDevelopment &&
|
|
- (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
|
|
|
|
|
|
+ ((info) =>
|
|
|
|
+ path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
|
|
// Prevents conflicts when multiple webpack runtimes (from different apps)
|
|
// Prevents conflicts when multiple webpack runtimes (from different apps)
|
|
// are used on the same page.
|
|
// are used on the same page.
|
|
jsonpFunction: `webpackJsonp${appPackageJson.name}`,
|
|
jsonpFunction: `webpackJsonp${appPackageJson.name}`,
|
|
@@ -268,7 +271,7 @@ module.exports = function(webpackEnv) {
|
|
// https://twitter.com/wSokra/status/969679223278505985
|
|
// https://twitter.com/wSokra/status/969679223278505985
|
|
// https://github.com/facebook/create-react-app/issues/5358
|
|
// https://github.com/facebook/create-react-app/issues/5358
|
|
runtimeChunk: {
|
|
runtimeChunk: {
|
|
- name: entrypoint => `runtime-${entrypoint.name}`,
|
|
|
|
|
|
+ name: (entrypoint) => `runtime-${entrypoint.name}`,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
resolve: {
|
|
resolve: {
|
|
@@ -286,8 +289,8 @@ module.exports = function(webpackEnv) {
|
|
// `web` extension prefixes have been added for better support
|
|
// `web` extension prefixes have been added for better support
|
|
// for React Native Web.
|
|
// for React Native Web.
|
|
extensions: paths.moduleFileExtensions
|
|
extensions: paths.moduleFileExtensions
|
|
- .map(ext => `.${ext}`)
|
|
|
|
- .filter(ext => useTypeScript || !ext.includes('ts')),
|
|
|
|
|
|
+ .map((ext) => `.${ext}`)
|
|
|
|
+ .filter((ext) => useTypeScript || !ext.includes('ts')),
|
|
alias: {
|
|
alias: {
|
|
// Support React Native Web
|
|
// Support React Native Web
|
|
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
|
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
|
@@ -336,7 +339,6 @@ module.exports = function(webpackEnv) {
|
|
formatter: require.resolve('react-dev-utils/eslintFormatter'),
|
|
formatter: require.resolve('react-dev-utils/eslintFormatter'),
|
|
eslintPath: require.resolve('eslint'),
|
|
eslintPath: require.resolve('eslint'),
|
|
resolvePluginsRelativeTo: __dirname,
|
|
resolvePluginsRelativeTo: __dirname,
|
|
-
|
|
|
|
},
|
|
},
|
|
loader: require.resolve('eslint-loader'),
|
|
loader: require.resolve('eslint-loader'),
|
|
},
|
|
},
|
|
@@ -369,7 +371,7 @@ module.exports = function(webpackEnv) {
|
|
customize: require.resolve(
|
|
customize: require.resolve(
|
|
'babel-preset-react-app/webpack-overrides'
|
|
'babel-preset-react-app/webpack-overrides'
|
|
),
|
|
),
|
|
-
|
|
|
|
|
|
+
|
|
plugins: [
|
|
plugins: [
|
|
[
|
|
[
|
|
require.resolve('babel-plugin-named-asset-import'),
|
|
require.resolve('babel-plugin-named-asset-import'),
|
|
@@ -411,7 +413,7 @@ module.exports = function(webpackEnv) {
|
|
cacheDirectory: true,
|
|
cacheDirectory: true,
|
|
// See #6846 for context on why cacheCompression is disabled
|
|
// See #6846 for context on why cacheCompression is disabled
|
|
cacheCompression: false,
|
|
cacheCompression: false,
|
|
-
|
|
|
|
|
|
+
|
|
// Babel sourcemaps are needed for debugging into node_modules
|
|
// Babel sourcemaps are needed for debugging into node_modules
|
|
// code. Without the options below, debuggers like VSCode
|
|
// code. Without the options below, debuggers like VSCode
|
|
// show incorrect code and set breakpoints on the wrong lines.
|
|
// show incorrect code and set breakpoints on the wrong lines.
|
|
@@ -485,6 +487,31 @@ module.exports = function(webpackEnv) {
|
|
'sass-loader'
|
|
'sass-loader'
|
|
),
|
|
),
|
|
},
|
|
},
|
|
|
|
+ // Less 解析配置
|
|
|
|
+ {
|
|
|
|
+ test: lessRegex,
|
|
|
|
+ exclude: lessModuleRegex,
|
|
|
|
+ use: getStyleLoaders(
|
|
|
|
+ {
|
|
|
|
+ importLoaders: 2,
|
|
|
|
+ sourceMap: isEnvProduction && shouldUseSourceMap,
|
|
|
|
+ },
|
|
|
|
+ 'less-loader'
|
|
|
|
+ ),
|
|
|
|
+ sideEffects: true,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ test: lessModuleRegex,
|
|
|
|
+ use: getStyleLoaders(
|
|
|
|
+ {
|
|
|
|
+ importLoaders: 2,
|
|
|
|
+ sourceMap: isEnvProduction && shouldUseSourceMap,
|
|
|
|
+ modules: true,
|
|
|
|
+ getLocalIdent: getCSSModuleLocalIdent,
|
|
|
|
+ },
|
|
|
|
+ 'less-loader'
|
|
|
|
+ ),
|
|
|
|
+ },
|
|
// "file" loader makes sure those assets get served by WebpackDevServer.
|
|
// "file" loader makes sure those assets get served by WebpackDevServer.
|
|
// When you `import` an asset, you get its (virtual) filename.
|
|
// When you `import` an asset, you get its (virtual) filename.
|
|
// In production, they would get copied to the `build` folder.
|
|
// In production, they would get copied to the `build` folder.
|
|
@@ -589,7 +616,7 @@ module.exports = function(webpackEnv) {
|
|
return manifest;
|
|
return manifest;
|
|
}, seed);
|
|
}, seed);
|
|
const entrypointFiles = entrypoints.main.filter(
|
|
const entrypointFiles = entrypoints.main.filter(
|
|
- fileName => !fileName.endsWith('.map')
|
|
|
|
|
|
+ (fileName) => !fileName.endsWith('.map')
|
|
);
|
|
);
|
|
|
|
|
|
return {
|
|
return {
|