@umijs/bundler-webpack 4.0.0-canary.20220429.1 → 4.0.0-canary.20220429.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/package.json +5 -5
  2. package/dist/build.d.ts +0 -20
  3. package/dist/build.js +0 -75
  4. package/dist/cli.d.ts +0 -1
  5. package/dist/cli.js +0 -90
  6. package/dist/client/client.d.ts +0 -1
  7. package/dist/client/client.js +0 -258
  8. package/dist/config/_sampleFeature.d.ts +0 -10
  9. package/dist/config/_sampleFeature.js +0 -22
  10. package/dist/config/assetRules.d.ts +0 -11
  11. package/dist/config/assetRules.js +0 -61
  12. package/dist/config/bundleAnalyzerPlugin.d.ts +0 -10
  13. package/dist/config/bundleAnalyzerPlugin.js +0 -30
  14. package/dist/config/compressPlugin.d.ts +0 -10
  15. package/dist/config/compressPlugin.js +0 -91
  16. package/dist/config/config.d.ts +0 -27
  17. package/dist/config/config.js +0 -226
  18. package/dist/config/copyPlugin.d.ts +0 -10
  19. package/dist/config/copyPlugin.js +0 -49
  20. package/dist/config/cssRules.d.ts +0 -11
  21. package/dist/config/cssRules.js +0 -98
  22. package/dist/config/definePlugin.d.ts +0 -15
  23. package/dist/config/definePlugin.js +0 -45
  24. package/dist/config/detectDeadCode.d.ts +0 -12
  25. package/dist/config/detectDeadCode.js +0 -120
  26. package/dist/config/detectDeadCodePlugin.d.ts +0 -9
  27. package/dist/config/detectDeadCodePlugin.js +0 -75
  28. package/dist/config/fastRefreshPlugin.d.ts +0 -12
  29. package/dist/config/fastRefreshPlugin.js +0 -34
  30. package/dist/config/forkTSCheckerPlugin.d.ts +0 -11
  31. package/dist/config/forkTSCheckerPlugin.js +0 -34
  32. package/dist/config/harmonyLinkingErrorPlugin.d.ts +0 -6
  33. package/dist/config/harmonyLinkingErrorPlugin.js +0 -42
  34. package/dist/config/ignorePlugin.d.ts +0 -10
  35. package/dist/config/ignorePlugin.js +0 -27
  36. package/dist/config/javaScriptRules.d.ts +0 -16
  37. package/dist/config/javaScriptRules.js +0 -188
  38. package/dist/config/manifestPlugin.d.ts +0 -11
  39. package/dist/config/manifestPlugin.js +0 -25
  40. package/dist/config/miniCSSExtractPlugin.d.ts +0 -11
  41. package/dist/config/miniCSSExtractPlugin.js +0 -33
  42. package/dist/config/nodePolyfill.d.ts +0 -10
  43. package/dist/config/nodePolyfill.js +0 -35
  44. package/dist/config/nodePrefixPlugin.d.ts +0 -11
  45. package/dist/config/nodePrefixPlugin.js +0 -25
  46. package/dist/config/progressPlugin.d.ts +0 -11
  47. package/dist/config/progressPlugin.js +0 -27
  48. package/dist/config/purgecssWebpackPlugin.d.ts +0 -10
  49. package/dist/config/purgecssWebpackPlugin.js +0 -32
  50. package/dist/config/speedMeasureWebpackPlugin.d.ts +0 -6
  51. package/dist/config/speedMeasureWebpackPlugin.js +0 -34
  52. package/dist/config/svgRules.d.ts +0 -12
  53. package/dist/config/svgRules.js +0 -57
  54. package/dist/constants.d.ts +0 -15
  55. package/dist/constants.js +0 -24
  56. package/dist/dev.d.ts +0 -25
  57. package/dist/dev.js +0 -145
  58. package/dist/index.d.ts +0 -8
  59. package/dist/index.js +0 -20
  60. package/dist/loader/svgr.d.ts +0 -4
  61. package/dist/loader/svgr.js +0 -67
  62. package/dist/loader/swc.d.ts +0 -4
  63. package/dist/loader/swc.js +0 -79
  64. package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +0 -11
  65. package/dist/plugins/ESBuildCSSMinifyPlugin.js +0 -63
  66. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +0 -10
  67. package/dist/plugins/ParcelCSSMinifyPlugin.js +0 -75
  68. package/dist/plugins/ProgressPlugin.d.ts +0 -15
  69. package/dist/plugins/ProgressPlugin.js +0 -44
  70. package/dist/plugins/RuntimePublicPathPlugin.d.ts +0 -4
  71. package/dist/plugins/RuntimePublicPathPlugin.js +0 -20
  72. package/dist/plugins/_SamplePlugin.d.ts +0 -9
  73. package/dist/plugins/_SamplePlugin.js +0 -14
  74. package/dist/requireHook.d.ts +0 -1
  75. package/dist/requireHook.js +0 -31
  76. package/dist/schema.d.ts +0 -3
  77. package/dist/schema.js +0 -84
  78. package/dist/server/server.d.ts +0 -17
  79. package/dist/server/server.js +0 -202
  80. package/dist/server/ws.d.ts +0 -11
  81. package/dist/server/ws.js +0 -42
  82. package/dist/swcPlugins/autoCSSModules.d.ts +0 -13
  83. package/dist/swcPlugins/autoCSSModules.js +0 -34
  84. package/dist/swcPlugins/changeImportFromString.d.ts +0 -2
  85. package/dist/swcPlugins/changeImportFromString.js +0 -10
  86. package/dist/swcPlugins/lockCoreJS.d.ts +0 -6
  87. package/dist/swcPlugins/lockCoreJS.js +0 -24
  88. package/dist/types.d.ts +0 -119
  89. package/dist/types.js +0 -30
  90. package/dist/utils/browsersList.d.ts +0 -5
  91. package/dist/utils/browsersList.js +0 -10
  92. package/dist/utils/depMatch.d.ts +0 -6
  93. package/dist/utils/depMatch.js +0 -46
  94. package/dist/utils/formatWebpackMessages.d.ts +0 -12
  95. package/dist/utils/formatWebpackMessages.js +0 -100
  96. package/dist/utils/getEsBuildTarget.d.ts +0 -5
  97. package/dist/utils/getEsBuildTarget.js +0 -12
@@ -1,91 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.addCompressPlugin = void 0;
16
- // @ts-ignore
17
- const css_minimizer_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/css-minimizer-webpack-plugin"));
18
- const terser_webpack_plugin_1 = __importDefault(require("../../compiled/terser-webpack-plugin"));
19
- const ESBuildCSSMinifyPlugin_1 = __importDefault(require("../plugins/ESBuildCSSMinifyPlugin"));
20
- const ParcelCSSMinifyPlugin_1 = require("../plugins/ParcelCSSMinifyPlugin");
21
- const types_1 = require("../types");
22
- const getEsBuildTarget_1 = require("../utils/getEsBuildTarget");
23
- function addCompressPlugin(opts) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const { config, userConfig, env } = opts;
26
- const jsMinifier = userConfig.jsMinifier || types_1.JSMinifier.esbuild;
27
- const cssMinifier = userConfig.cssMinifier || types_1.CSSMinifier.esbuild;
28
- if (env === types_1.Env.development ||
29
- process.env.COMPRESS === 'none' ||
30
- (jsMinifier === types_1.JSMinifier.none && cssMinifier === types_1.CSSMinifier.none)) {
31
- config.optimization.minimize(false);
32
- return;
33
- }
34
- config.optimization.minimize(true);
35
- let minify;
36
- let terserOptions;
37
- if (jsMinifier === types_1.JSMinifier.esbuild) {
38
- minify = terser_webpack_plugin_1.default.esbuildMinify;
39
- terserOptions = {
40
- target: (0, getEsBuildTarget_1.getEsBuildTarget)({
41
- targets: userConfig.targets || {},
42
- }),
43
- };
44
- }
45
- else if (jsMinifier === types_1.JSMinifier.terser) {
46
- minify = terser_webpack_plugin_1.default.terserMinify;
47
- }
48
- else if (jsMinifier === types_1.JSMinifier.swc) {
49
- minify = terser_webpack_plugin_1.default.swcMinify;
50
- }
51
- else if (jsMinifier === types_1.JSMinifier.uglifyJs) {
52
- minify = terser_webpack_plugin_1.default.uglifyJsMinify;
53
- }
54
- else if (jsMinifier !== types_1.JSMinifier.none) {
55
- throw new Error(`Unsupported jsMinifier ${userConfig.jsMinifier}.`);
56
- }
57
- terserOptions = Object.assign(Object.assign({}, terserOptions), userConfig.jsMinifierOptions);
58
- if (jsMinifier !== types_1.JSMinifier.none) {
59
- config.optimization.minimizer(`js-${jsMinifier}`).use(terser_webpack_plugin_1.default, [
60
- {
61
- minify,
62
- terserOptions,
63
- },
64
- ]);
65
- }
66
- if (cssMinifier === types_1.CSSMinifier.esbuild) {
67
- config.optimization
68
- .minimizer(`css-${cssMinifier}`)
69
- .use(ESBuildCSSMinifyPlugin_1.default, [userConfig.cssMinifierOptions]);
70
- }
71
- else if (cssMinifier === types_1.CSSMinifier.cssnano) {
72
- config.optimization
73
- .minimizer(`css-${cssMinifier}`)
74
- .use(css_minimizer_webpack_plugin_1.default, [
75
- {
76
- minimizerOptions: userConfig.cssMinifierOptions,
77
- parallel: true,
78
- },
79
- ]);
80
- }
81
- else if (cssMinifier === types_1.CSSMinifier.parcelCSS) {
82
- config.optimization
83
- .minimizer(`css-${cssMinifier}`)
84
- .use(ParcelCSSMinifyPlugin_1.ParcelCSSMinifyPlugin);
85
- }
86
- else if (cssMinifier !== types_1.CSSMinifier.none) {
87
- throw new Error(`Unsupported cssMinifier ${userConfig.cssMinifier}.`);
88
- }
89
- });
90
- }
91
- exports.addCompressPlugin = addCompressPlugin;
@@ -1,27 +0,0 @@
1
- import { Configuration } from '../../compiled/webpack';
2
- import { Env, IConfig } from '../types';
3
- export interface IOpts {
4
- cwd: string;
5
- rootDir?: string;
6
- env: Env;
7
- entry: Record<string, string>;
8
- extraBabelPresets?: any[];
9
- extraBabelPlugins?: any[];
10
- extraBabelIncludes?: string[];
11
- extraEsbuildLoaderHandler?: any[];
12
- babelPreset?: any;
13
- chainWebpack?: Function;
14
- modifyWebpackConfig?: Function;
15
- hash?: boolean;
16
- hmr?: boolean;
17
- staticPathPrefix?: string;
18
- userConfig: IConfig;
19
- analyze?: any;
20
- name?: string;
21
- cache?: {
22
- absNodeModulesPath?: string;
23
- buildDependencies?: string[];
24
- cacheDirectory?: string;
25
- };
26
- }
27
- export declare function getConfig(opts: IOpts): Promise<Configuration>;
@@ -1,226 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getConfig = void 0;
16
- const path_1 = require("path");
17
- const webpack_1 = __importDefault(require("../../compiled/webpack"));
18
- const webpack_5_chain_1 = __importDefault(require("../../compiled/webpack-5-chain"));
19
- const constants_1 = require("../constants");
20
- const RuntimePublicPathPlugin_1 = require("../plugins/RuntimePublicPathPlugin");
21
- const types_1 = require("../types");
22
- const browsersList_1 = require("../utils/browsersList");
23
- const assetRules_1 = require("./assetRules");
24
- const bundleAnalyzerPlugin_1 = require("./bundleAnalyzerPlugin");
25
- const compressPlugin_1 = require("./compressPlugin");
26
- const copyPlugin_1 = require("./copyPlugin");
27
- const cssRules_1 = require("./cssRules");
28
- const definePlugin_1 = require("./definePlugin");
29
- const detectDeadCodePlugin_1 = require("./detectDeadCodePlugin");
30
- const fastRefreshPlugin_1 = require("./fastRefreshPlugin");
31
- const forkTSCheckerPlugin_1 = require("./forkTSCheckerPlugin");
32
- const harmonyLinkingErrorPlugin_1 = require("./harmonyLinkingErrorPlugin");
33
- const ignorePlugin_1 = require("./ignorePlugin");
34
- const javaScriptRules_1 = require("./javaScriptRules");
35
- const manifestPlugin_1 = require("./manifestPlugin");
36
- const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
37
- const nodePolyfill_1 = require("./nodePolyfill");
38
- const progressPlugin_1 = require("./progressPlugin");
39
- const speedMeasureWebpackPlugin_1 = require("./speedMeasureWebpackPlugin");
40
- const svgRules_1 = require("./svgRules");
41
- function getConfig(opts) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const { userConfig } = opts;
44
- const isDev = opts.env === types_1.Env.development;
45
- const config = new webpack_5_chain_1.default();
46
- userConfig.targets || (userConfig.targets = constants_1.DEFAULT_BROWSER_TARGETS);
47
- const useHash = !!(opts.hash || (userConfig.hash && !isDev));
48
- const applyOpts = {
49
- name: opts.name,
50
- config,
51
- userConfig,
52
- cwd: opts.cwd,
53
- env: opts.env,
54
- babelPreset: opts.babelPreset,
55
- extraBabelPlugins: opts.extraBabelPlugins || [],
56
- extraBabelPresets: opts.extraBabelPresets || [],
57
- extraBabelIncludes: opts.extraBabelIncludes || [],
58
- extraEsbuildLoaderHandler: opts.extraEsbuildLoaderHandler || [],
59
- browsers: (0, browsersList_1.getBrowsersList)({
60
- targets: userConfig.targets,
61
- }),
62
- useHash,
63
- staticPathPrefix: opts.staticPathPrefix !== undefined ? opts.staticPathPrefix : 'static/',
64
- };
65
- // mode
66
- config.mode(opts.env);
67
- config.stats('none');
68
- // entry
69
- Object.keys(opts.entry).forEach((key) => {
70
- const entry = config.entry(key);
71
- if (isDev && opts.hmr) {
72
- entry.add(require.resolve('../../client/client/client'));
73
- }
74
- entry.add(opts.entry[key]);
75
- });
76
- // devtool
77
- config.devtool(isDev
78
- ? userConfig.devtool === false
79
- ? false
80
- : userConfig.devtool || constants_1.DEFAULT_DEVTOOL
81
- : userConfig.devtool);
82
- // output
83
- const absOutputPath = (0, path_1.join)(opts.cwd, userConfig.outputPath || constants_1.DEFAULT_OUTPUT_PATH);
84
- const disableCompress = process.env.COMPRESS === 'none';
85
- config.output
86
- .path(absOutputPath)
87
- .filename(useHash ? `[name].[contenthash:8].js` : `[name].js`)
88
- .chunkFilename(useHash ? `[name].[contenthash:8].async.js` : `[name].js`)
89
- .publicPath(userConfig.publicPath || 'auto')
90
- .pathinfo(isDev || disableCompress);
91
- // resolve
92
- // prettier-ignore
93
- config.resolve
94
- .set('symlinks', true)
95
- .modules
96
- .add('node_modules')
97
- .end()
98
- .alias
99
- .merge(userConfig.alias || {})
100
- .end()
101
- .extensions
102
- .merge([
103
- '.wasm',
104
- '.mjs',
105
- '.js',
106
- '.jsx',
107
- '.ts',
108
- '.tsx',
109
- '.json'
110
- ])
111
- .end();
112
- // externals
113
- config.externals(userConfig.externals || []);
114
- // target
115
- config.target(['web', 'es5']);
116
- // experiments
117
- config.experiments({
118
- topLevelAwait: true,
119
- outputModule: !!userConfig.esm,
120
- });
121
- // node polyfill
122
- yield (0, nodePolyfill_1.addNodePolyfill)(applyOpts);
123
- // rules
124
- yield (0, javaScriptRules_1.addJavaScriptRules)(applyOpts);
125
- yield (0, cssRules_1.addCSSRules)(applyOpts);
126
- yield (0, assetRules_1.addAssetRules)(applyOpts);
127
- yield (0, svgRules_1.addSVGRules)(applyOpts);
128
- // plugins
129
- // mini-css-extract-plugin
130
- yield (0, miniCSSExtractPlugin_1.addMiniCSSExtractPlugin)(applyOpts);
131
- // ignoreMomentLocale
132
- yield (0, ignorePlugin_1.addIgnorePlugin)(applyOpts);
133
- // define
134
- yield (0, definePlugin_1.addDefinePlugin)(applyOpts);
135
- // fast refresh
136
- yield (0, fastRefreshPlugin_1.addFastRefreshPlugin)(applyOpts);
137
- // progress
138
- yield (0, progressPlugin_1.addProgressPlugin)(applyOpts);
139
- // detect-dead-code-plugin
140
- yield (0, detectDeadCodePlugin_1.addDetectDeadCodePlugin)(applyOpts);
141
- // fork-ts-checker
142
- yield (0, forkTSCheckerPlugin_1.addForkTSCheckerPlugin)(applyOpts);
143
- // copy
144
- yield (0, copyPlugin_1.addCopyPlugin)(applyOpts);
145
- // manifest
146
- yield (0, manifestPlugin_1.addManifestPlugin)(applyOpts);
147
- // hmr
148
- if (isDev && opts.hmr) {
149
- config.plugin('hmr').use(webpack_1.default.HotModuleReplacementPlugin);
150
- }
151
- // compress
152
- yield (0, compressPlugin_1.addCompressPlugin)(applyOpts);
153
- // purgecss
154
- // await applyPurgeCSSWebpackPlugin(applyOpts);
155
- // handle HarmonyLinkingError
156
- yield (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
157
- // remove node: prefix
158
- // disable for performance
159
- // await addNodePrefixPlugin(applyOpts);
160
- // runtimePublicPath
161
- if (userConfig.runtimePublicPath) {
162
- config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
163
- }
164
- // cache
165
- if (opts.cache) {
166
- config.cache({
167
- type: 'filesystem',
168
- version: require('../../package.json').version,
169
- buildDependencies: {
170
- config: opts.cache.buildDependencies || [],
171
- },
172
- cacheDirectory: opts.cache.cacheDirectory ||
173
- // 使用 rootDir 是在有 APP_ROOT 时,把 cache 目录放在根目录下
174
- (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules', '.cache', 'bundler-webpack'),
175
- });
176
- // tnpm 安装依赖的情况 webpack 默认的 managedPaths 不生效
177
- // 使用 immutablePaths 避免 node_modules 的内容被写入缓存
178
- // tnpm 安装的依赖路径中同时包含包名和版本号,满足 immutablePaths 使用的条件
179
- // ref: smallfish
180
- if ( /*isTnpm*/require('@umijs/utils/package').__npminstall_done) {
181
- config.snapshot({
182
- immutablePaths: [
183
- opts.cache.absNodeModulesPath ||
184
- (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules'),
185
- ],
186
- });
187
- }
188
- config.infrastructureLogging(Object.assign({ level: 'error' }, (process.env.WEBPACK_FS_CACHE_DEBUG
189
- ? {
190
- debug: /webpack\.cache/,
191
- }
192
- : {})));
193
- }
194
- // analyzer
195
- if (opts.analyze) {
196
- yield (0, bundleAnalyzerPlugin_1.addBundleAnalyzerPlugin)(applyOpts);
197
- }
198
- // chain webpack
199
- if (opts.chainWebpack) {
200
- yield opts.chainWebpack(config, {
201
- env: opts.env,
202
- webpack: webpack_1.default,
203
- });
204
- }
205
- if (userConfig.chainWebpack) {
206
- yield userConfig.chainWebpack(config, {
207
- env: opts.env,
208
- webpack: webpack_1.default,
209
- });
210
- }
211
- let webpackConfig = config.toConfig();
212
- // speed measure
213
- // TODO: mini-css-extract-plugin 报错
214
- webpackConfig = yield (0, speedMeasureWebpackPlugin_1.addSpeedMeasureWebpackPlugin)({
215
- webpackConfig,
216
- });
217
- if (opts.modifyWebpackConfig) {
218
- webpackConfig = yield opts.modifyWebpackConfig(webpackConfig, {
219
- env: opts.env,
220
- webpack: webpack_1.default,
221
- });
222
- }
223
- return webpackConfig;
224
- });
225
- }
226
- exports.getConfig = getConfig;
@@ -1,10 +0,0 @@
1
- import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
- import { Env, IConfig } from '../types';
3
- interface IOpts {
4
- config: Config;
5
- userConfig: IConfig;
6
- cwd: string;
7
- env: Env;
8
- }
9
- export declare function addCopyPlugin(opts: IOpts): Promise<void>;
10
- export {};
@@ -1,49 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.addCopyPlugin = void 0;
13
- const fs_1 = require("fs");
14
- const path_1 = require("path");
15
- function addCopyPlugin(opts) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { config, userConfig, cwd } = opts;
18
- const copyPatterns = [
19
- (0, fs_1.existsSync)((0, path_1.join)(cwd, 'public')) && {
20
- from: (0, path_1.join)(cwd, 'public'),
21
- },
22
- ...(userConfig.copy
23
- ? userConfig.copy.map((item) => {
24
- if (typeof item === 'string') {
25
- return {
26
- from: (0, path_1.join)(cwd, item),
27
- to: item,
28
- };
29
- }
30
- return {
31
- // 相对于 process.cwd,所以这里需要使用绝对路径
32
- from: (0, path_1.join)(cwd, item.from),
33
- to: item.to,
34
- };
35
- })
36
- : []),
37
- ].filter(Boolean);
38
- if (copyPatterns.length) {
39
- config
40
- .plugin('copy')
41
- .use(require('@umijs/bundler-webpack/compiled/copy-webpack-plugin'), [
42
- {
43
- patterns: copyPatterns,
44
- },
45
- ]);
46
- }
47
- });
48
- }
49
- exports.addCopyPlugin = addCopyPlugin;
@@ -1,11 +0,0 @@
1
- import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
- import { Env, IConfig } from '../types';
3
- interface IOpts {
4
- config: Config;
5
- userConfig: IConfig;
6
- cwd: string;
7
- env: Env;
8
- browsers: any;
9
- }
10
- export declare function addCSSRules(opts: IOpts): Promise<void>;
11
- export {};
@@ -1,98 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.addCSSRules = void 0;
13
- function addCSSRules(opts) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- const { config, userConfig } = opts;
16
- const rulesConfig = [
17
- { name: 'css', test: /\.css(\?.*)?$/ },
18
- {
19
- name: 'less',
20
- test: /\.less(\?.*)?$/,
21
- loader: require.resolve('@umijs/bundler-webpack/compiled/less-loader'),
22
- loaderOptions: {
23
- implementation: require.resolve('@umijs/bundler-utils/compiled/less'),
24
- lessOptions: Object.assign({ modifyVars: userConfig.theme, javascriptEnabled: true }, userConfig.lessLoader),
25
- },
26
- },
27
- {
28
- name: 'sass',
29
- test: /\.(sass|scss)(\?.*)?$/,
30
- loader: require.resolve('@umijs/bundler-webpack/compiled/sass-loader'),
31
- loaderOptions: userConfig.sassLoader || {},
32
- },
33
- ];
34
- for (const { name, test, loader, loaderOptions } of rulesConfig) {
35
- const rule = config.module.rule(name);
36
- const nestRulesConfig = [
37
- userConfig.autoCSSModules && {
38
- rule: rule
39
- .test(test)
40
- .oneOf('css-modules')
41
- .resourceQuery(/modules/),
42
- isCSSModules: true,
43
- },
44
- {
45
- rule: rule.test(test).oneOf('css').sideEffects(true),
46
- isCSSModules: false,
47
- },
48
- ].filter(Boolean);
49
- // @ts-ignore
50
- for (const { rule, isCSSModules } of nestRulesConfig) {
51
- if (userConfig.styleLoader) {
52
- rule
53
- .use('style-loader')
54
- .loader(require.resolve('@umijs/bundler-webpack/compiled/style-loader'))
55
- .options(Object.assign({ base: 0, esModule: true }, userConfig.styleLoader));
56
- }
57
- else {
58
- rule
59
- .use('mini-css-extract-plugin')
60
- .loader(require.resolve('@umijs/bundler-webpack/compiled/mini-css-extract-plugin/loader'))
61
- .options({
62
- publicPath: './',
63
- emit: true,
64
- esModule: true,
65
- });
66
- }
67
- rule
68
- .use('css-loader')
69
- .loader(require.resolve('css-loader'))
70
- .options(Object.assign(Object.assign({ importLoaders: 1, esModule: true, url: true, import: true }, (isCSSModules
71
- ? {
72
- modules: Object.assign({ localIdentName: '[local]___[hash:base64:5]' }, userConfig.cssLoaderModules),
73
- }
74
- : {})), userConfig.cssLoader));
75
- rule
76
- .use('postcss-loader')
77
- .loader(require.resolve('@umijs/bundler-webpack/compiled/postcss-loader'))
78
- .options({
79
- postcssOptions: Object.assign({ ident: 'postcss', plugins: [
80
- require('@umijs/bundler-webpack/compiled/postcss-flexbugs-fixes'),
81
- require('postcss-preset-env')({
82
- browsers: opts.browsers,
83
- autoprefixer: Object.assign({ flexbox: 'no-2009' }, userConfig.autoprefixer),
84
- stage: 3,
85
- }),
86
- ].concat(userConfig.extraPostCSSPlugins || []) }, userConfig.postcssLoader),
87
- });
88
- if (loader) {
89
- rule
90
- .use(loader)
91
- .loader(typeof loader === 'string' ? require.resolve(loader) : loader)
92
- .options(loaderOptions || {});
93
- }
94
- }
95
- }
96
- });
97
- }
98
- exports.addCSSRules = addCSSRules;
@@ -1,15 +0,0 @@
1
- import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
- import { Env, IConfig } from '../types';
3
- interface IOpts {
4
- config: Config;
5
- userConfig: IConfig;
6
- cwd: string;
7
- env: Env;
8
- }
9
- export declare function resolveDefine(opts: {
10
- define: any;
11
- }): {
12
- 'process.env': Record<string, any>;
13
- };
14
- export declare function addDefinePlugin(opts: IOpts): Promise<void>;
15
- export {};
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.addDefinePlugin = exports.resolveDefine = void 0;
13
- const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
14
- const prefixRE = /^UMI_APP_/;
15
- const ENV_SHOULD_PASS = ['NODE_ENV', 'HMR', 'SOCKET_SERVER', 'ERROR_OVERLAY'];
16
- function resolveDefine(opts) {
17
- const env = {};
18
- Object.keys(process.env).forEach((key) => {
19
- if (prefixRE.test(key) || ENV_SHOULD_PASS.includes(key)) {
20
- env[key] = process.env[key];
21
- }
22
- });
23
- for (const key in env) {
24
- env[key] = JSON.stringify(env[key]);
25
- }
26
- const define = {};
27
- if (opts.define) {
28
- for (const key in opts.define) {
29
- define[key] = JSON.stringify(opts.define[key]);
30
- }
31
- }
32
- return Object.assign({ 'process.env': env }, define);
33
- }
34
- exports.resolveDefine = resolveDefine;
35
- function addDefinePlugin(opts) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const { config, userConfig } = opts;
38
- config.plugin('define').use(webpack_1.DefinePlugin, [
39
- resolveDefine({
40
- define: userConfig.define || {},
41
- }),
42
- ]);
43
- });
44
- }
45
- exports.addDefinePlugin = addDefinePlugin;
@@ -1,12 +0,0 @@
1
- import { Compilation } from '@umijs/bundler-webpack/compiled/webpack';
2
- import { DeadCodeParams } from '../types';
3
- export interface Options extends DeadCodeParams {
4
- patterns: string[];
5
- exclude: string[];
6
- failOnHint: boolean;
7
- detectUnusedFiles: boolean;
8
- detectUnusedExport: boolean;
9
- }
10
- export declare const disabledFolders: string[];
11
- declare const detectDeadCode: (compilation: Compilation, options: Options) => void;
12
- export default detectDeadCode;