@umijs/bundler-webpack 4.0.0-canary.20220429.3 → 4.0.0-canary.20220506.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/dist/build.d.ts +20 -0
  2. package/dist/build.js +64 -0
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.js +81 -0
  5. package/dist/client/client.d.ts +1 -0
  6. package/dist/client/client.js +245 -0
  7. package/dist/config/_sampleFeature.d.ts +10 -0
  8. package/dist/config/_sampleFeature.js +11 -0
  9. package/dist/config/assetRules.d.ts +11 -0
  10. package/dist/config/assetRules.js +50 -0
  11. package/dist/config/bundleAnalyzerPlugin.d.ts +10 -0
  12. package/dist/config/bundleAnalyzerPlugin.js +19 -0
  13. package/dist/config/compressPlugin.d.ts +10 -0
  14. package/dist/config/compressPlugin.js +83 -0
  15. package/dist/config/config.d.ts +27 -0
  16. package/dist/config/config.js +218 -0
  17. package/dist/config/copyPlugin.d.ts +10 -0
  18. package/dist/config/copyPlugin.js +38 -0
  19. package/dist/config/cssRules.d.ts +11 -0
  20. package/dist/config/cssRules.js +108 -0
  21. package/dist/config/definePlugin.d.ts +15 -0
  22. package/dist/config/definePlugin.js +37 -0
  23. package/dist/config/detectDeadCode.d.ts +12 -0
  24. package/dist/config/detectDeadCode.js +120 -0
  25. package/dist/config/detectDeadCodePlugin.d.ts +9 -0
  26. package/dist/config/detectDeadCodePlugin.js +70 -0
  27. package/dist/config/fastRefreshPlugin.d.ts +12 -0
  28. package/dist/config/fastRefreshPlugin.js +23 -0
  29. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  30. package/dist/config/forkTSCheckerPlugin.js +23 -0
  31. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  32. package/dist/config/harmonyLinkingErrorPlugin.js +31 -0
  33. package/dist/config/ignorePlugin.d.ts +10 -0
  34. package/dist/config/ignorePlugin.js +16 -0
  35. package/dist/config/javaScriptRules.d.ts +16 -0
  36. package/dist/config/javaScriptRules.js +177 -0
  37. package/dist/config/manifestPlugin.d.ts +11 -0
  38. package/dist/config/manifestPlugin.js +17 -0
  39. package/dist/config/miniCSSExtractPlugin.d.ts +11 -0
  40. package/dist/config/miniCSSExtractPlugin.js +22 -0
  41. package/dist/config/nodePolyfill.d.ts +10 -0
  42. package/dist/config/nodePolyfill.js +28 -0
  43. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  44. package/dist/config/nodePrefixPlugin.js +14 -0
  45. package/dist/config/progressPlugin.d.ts +11 -0
  46. package/dist/config/progressPlugin.js +16 -0
  47. package/dist/config/purgecssWebpackPlugin.d.ts +10 -0
  48. package/dist/config/purgecssWebpackPlugin.js +21 -0
  49. package/dist/config/speedMeasureWebpackPlugin.d.ts +6 -0
  50. package/dist/config/speedMeasureWebpackPlugin.js +23 -0
  51. package/dist/config/svgRules.d.ts +12 -0
  52. package/dist/config/svgRules.js +53 -0
  53. package/dist/constants.d.ts +15 -0
  54. package/dist/constants.js +24 -0
  55. package/dist/dev.d.ts +25 -0
  56. package/dist/dev.js +134 -0
  57. package/dist/index.d.ts +8 -0
  58. package/dist/index.js +20 -0
  59. package/dist/loader/svgr.d.ts +4 -0
  60. package/dist/loader/svgr.js +58 -0
  61. package/dist/loader/swc.d.ts +4 -0
  62. package/dist/loader/swc.js +74 -0
  63. package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +11 -0
  64. package/dist/plugins/ESBuildCSSMinifyPlugin.js +52 -0
  65. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
  66. package/dist/plugins/ParcelCSSMinifyPlugin.js +73 -0
  67. package/dist/plugins/ProgressPlugin.d.ts +15 -0
  68. package/dist/plugins/ProgressPlugin.js +44 -0
  69. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  70. package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
  71. package/dist/plugins/_SamplePlugin.d.ts +9 -0
  72. package/dist/plugins/_SamplePlugin.js +14 -0
  73. package/dist/requireHook.d.ts +1 -0
  74. package/dist/requireHook.js +31 -0
  75. package/dist/schema.d.ts +3 -0
  76. package/dist/schema.js +84 -0
  77. package/dist/server/server.d.ts +17 -0
  78. package/dist/server/server.js +193 -0
  79. package/dist/server/ws.d.ts +11 -0
  80. package/dist/server/ws.js +42 -0
  81. package/dist/swcPlugins/autoCSSModules.d.ts +13 -0
  82. package/dist/swcPlugins/autoCSSModules.js +34 -0
  83. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  84. package/dist/swcPlugins/changeImportFromString.js +10 -0
  85. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  86. package/dist/swcPlugins/lockCoreJS.js +24 -0
  87. package/dist/types.d.ts +119 -0
  88. package/dist/types.js +30 -0
  89. package/dist/utils/browsersList.d.ts +5 -0
  90. package/dist/utils/browsersList.js +10 -0
  91. package/dist/utils/depMatch.d.ts +6 -0
  92. package/dist/utils/depMatch.js +46 -0
  93. package/dist/utils/formatWebpackMessages.d.ts +12 -0
  94. package/dist/utils/formatWebpackMessages.js +100 -0
  95. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  96. package/dist/utils/getEsBuildTarget.js +12 -0
  97. package/package.json +5 -5
package/dist/dev.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { IOpts as IConfigOpts } from './config/config';
2
+ import { IConfig } from './types';
3
+ declare type IOpts = {
4
+ afterMiddlewares?: any[];
5
+ beforeMiddlewares?: any[];
6
+ onDevCompileDone?: Function;
7
+ onProgress?: Function;
8
+ onMFSUProgress?: Function;
9
+ port?: number;
10
+ host?: string;
11
+ babelPreset?: any;
12
+ chainWebpack?: Function;
13
+ modifyWebpackConfig?: Function;
14
+ beforeBabelPlugins?: any[];
15
+ beforeBabelPresets?: any[];
16
+ extraBabelPlugins?: any[];
17
+ extraBabelPresets?: any[];
18
+ cwd: string;
19
+ rootDir?: string;
20
+ config: IConfig;
21
+ entry: Record<string, string>;
22
+ } & Pick<IConfigOpts, 'cache'>;
23
+ export declare function stripUndefined(obj: any): any;
24
+ export declare function dev(opts: IOpts): Promise<void>;
25
+ export {};
package/dist/dev.js ADDED
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.dev = exports.stripUndefined = void 0;
7
+ const mfsu_1 = require("@umijs/mfsu");
8
+ const utils_1 = require("@umijs/utils");
9
+ const fs_1 = require("fs");
10
+ const path_1 = require("path");
11
+ const webpack_1 = __importDefault(require("../compiled/webpack"));
12
+ const config_1 = require("./config/config");
13
+ const constants_1 = require("./constants");
14
+ const server_1 = require("./server/server");
15
+ const types_1 = require("./types");
16
+ function stripUndefined(obj) {
17
+ Object.keys(obj).forEach((key) => {
18
+ if (obj[key] === undefined) {
19
+ delete obj[key];
20
+ }
21
+ });
22
+ return obj;
23
+ }
24
+ exports.stripUndefined = stripUndefined;
25
+ async function dev(opts) {
26
+ var _a, _b, _c, _d, _e, _f;
27
+ var _g;
28
+ const enableMFSU = opts.config.mfsu !== false;
29
+ let mfsu = null;
30
+ if (enableMFSU) {
31
+ if (opts.config.srcTranspiler === types_1.Transpiler.swc) {
32
+ utils_1.logger.warn(`Swc currently not supported for use with mfsu, recommended you use srcTranspiler: 'esbuild' in dev.`);
33
+ }
34
+ mfsu = new mfsu_1.MFSU({
35
+ implementor: webpack_1.default,
36
+ buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
37
+ depBuildConfig: {
38
+ extraPostCSSPlugins: ((_b = opts.config) === null || _b === void 0 ? void 0 : _b.extraPostCSSPlugins) || [],
39
+ },
40
+ mfName: (_c = opts.config.mfsu) === null || _c === void 0 ? void 0 : _c.mfName,
41
+ runtimePublicPath: opts.config.runtimePublicPath,
42
+ tmpBase: ((_d = opts.config.mfsu) === null || _d === void 0 ? void 0 : _d.cacheDirectory) ||
43
+ (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules/.cache/mfsu'),
44
+ onMFSUProgress: opts.onMFSUProgress,
45
+ getCacheDependency() {
46
+ return stripUndefined({
47
+ version: require('../package.json').version,
48
+ mfsu: opts.config.mfsu,
49
+ alias: opts.config.alias,
50
+ externals: opts.config.externals,
51
+ theme: opts.config.theme,
52
+ runtimePublicPath: opts.config.runtimePublicPath,
53
+ publicPath: opts.config.publicPath,
54
+ });
55
+ },
56
+ });
57
+ }
58
+ const webpackConfig = await (0, config_1.getConfig)({
59
+ cwd: opts.cwd,
60
+ rootDir: opts.rootDir,
61
+ env: types_1.Env.development,
62
+ entry: opts.entry,
63
+ userConfig: opts.config,
64
+ babelPreset: opts.babelPreset,
65
+ extraBabelPlugins: [
66
+ ...(opts.beforeBabelPlugins || []),
67
+ ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getBabelPlugins()) || []),
68
+ ...(opts.extraBabelPlugins || []),
69
+ ],
70
+ extraBabelPresets: [
71
+ ...(opts.beforeBabelPresets || []),
72
+ ...(opts.extraBabelPresets || []),
73
+ ],
74
+ extraBabelIncludes: opts.config.extraBabelIncludes,
75
+ extraEsbuildLoaderHandler: (mfsu === null || mfsu === void 0 ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
76
+ chainWebpack: opts.chainWebpack,
77
+ modifyWebpackConfig: opts.modifyWebpackConfig,
78
+ hmr: true,
79
+ analyze: process.env.ANALYZE,
80
+ cache: opts.cache,
81
+ });
82
+ const depConfig = await (0, config_1.getConfig)({
83
+ cwd: opts.cwd,
84
+ rootDir: opts.rootDir,
85
+ env: types_1.Env.development,
86
+ entry: opts.entry,
87
+ userConfig: opts.config,
88
+ hash: true,
89
+ staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
90
+ name: constants_1.MFSU_NAME,
91
+ chainWebpack: (_e = opts.config.mfsu) === null || _e === void 0 ? void 0 : _e.chainWebpack,
92
+ cache: {
93
+ buildDependencies: (_f = opts.cache) === null || _f === void 0 ? void 0 : _f.buildDependencies,
94
+ cacheDirectory: (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
95
+ },
96
+ });
97
+ (_g = webpackConfig.resolve).alias || (_g.alias = {});
98
+ // TODO: REMOVE ME
99
+ ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
100
+ // @ts-ignore
101
+ webpackConfig.resolve.alias[dep] = require.resolve(dep);
102
+ });
103
+ await (mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
104
+ config: webpackConfig,
105
+ depConfig: depConfig,
106
+ }));
107
+ if (mfsu &&
108
+ webpackConfig.cache &&
109
+ typeof webpackConfig.cache === 'object' &&
110
+ webpackConfig.cache.type === 'filesystem') {
111
+ const webpackCachePath = (0, path_1.join)(webpackConfig.cache.cacheDirectory, `default-development`, 'index.pack');
112
+ const mfsuCacheExists = (0, fs_1.existsSync)(mfsu.depInfo.cacheFilePath);
113
+ const webpackCacheExists = (0, fs_1.existsSync)(webpackCachePath);
114
+ if (webpackCacheExists && !mfsuCacheExists) {
115
+ utils_1.logger.warn(`Invalidate webpack cache since mfsu cache is missing`);
116
+ utils_1.rimraf.sync(webpackConfig.cache.cacheDirectory);
117
+ }
118
+ }
119
+ await (0, server_1.createServer)({
120
+ webpackConfig,
121
+ userConfig: opts.config,
122
+ cwd: opts.cwd,
123
+ beforeMiddlewares: [
124
+ ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getMiddlewares()) || []),
125
+ ...(opts.beforeMiddlewares || []),
126
+ ],
127
+ port: opts.port,
128
+ host: opts.host,
129
+ afterMiddlewares: [...(opts.afterMiddlewares || [])],
130
+ onDevCompileDone: opts.onDevCompileDone,
131
+ onProgress: opts.onProgress,
132
+ });
133
+ }
134
+ exports.dev = dev;
@@ -0,0 +1,8 @@
1
+ import type webpack from '../compiled/webpack';
2
+ export type { RequestHandler } from '@umijs/bundler-utils/compiled/express';
3
+ export type { Compiler, Stats } from '../compiled/webpack';
4
+ export * from './build';
5
+ export * from './config/config';
6
+ export * from './dev';
7
+ export * from './schema';
8
+ export { webpack };
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./build"), exports);
18
+ __exportStar(require("./config/config"), exports);
19
+ __exportStar(require("./dev"), exports);
20
+ __exportStar(require("./schema"), exports);
@@ -0,0 +1,4 @@
1
+ import { Config } from '@svgr/core';
2
+ import type { LoaderContext } from '../../compiled/webpack';
3
+ declare function svgrLoader(this: LoaderContext<Config>, contents: string): void;
4
+ export default svgrLoader;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // MIT: https://github.com/gregberge/svgr/blob/main/packages/webpack/src/index.ts
7
+ // TODO: prebuild @svgr/core @svgr/plugin-jsx @svgr/plugin-svgo
8
+ const core_1 = require("@svgr/core");
9
+ // @ts-ignore
10
+ const plugin_jsx_1 = __importDefault(require("@svgr/plugin-jsx"));
11
+ // @ts-ignore
12
+ const plugin_svgo_1 = __importDefault(require("@svgr/plugin-svgo"));
13
+ const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
14
+ const path_1 = require("path");
15
+ const util_1 = require("util");
16
+ const tranformSvg = (0, util_1.callbackify)(async (contents, options, state) => {
17
+ const jsCode = await (0, core_1.transform)(contents, options, state);
18
+ const result = await (0, esbuild_1.transform)(jsCode, {
19
+ loader: 'tsx',
20
+ target: 'es2015',
21
+ });
22
+ if (!(result === null || result === void 0 ? void 0 : result.code)) {
23
+ throw new Error(`Error while transforming using Esbuild`);
24
+ }
25
+ return result.code;
26
+ });
27
+ function svgrLoader(contents) {
28
+ this.cacheable && this.cacheable();
29
+ const callback = this.async();
30
+ const options = this.getOptions();
31
+ const previousExport = (() => {
32
+ if (contents.startsWith('export '))
33
+ return contents;
34
+ const exportMatches = contents.match(/^module.exports\s*=\s*(.*)/);
35
+ return exportMatches ? `export default ${exportMatches[1]}` : null;
36
+ })();
37
+ const state = {
38
+ caller: {
39
+ name: 'svgr-loader',
40
+ previousExport,
41
+ defaultPlugins: [plugin_svgo_1.default, plugin_jsx_1.default],
42
+ },
43
+ filePath: (0, path_1.normalize)(this.resourcePath),
44
+ };
45
+ if (!previousExport) {
46
+ tranformSvg(contents, options, state, callback);
47
+ }
48
+ else {
49
+ this.fs.readFile(this.resourcePath, (err, result) => {
50
+ if (err) {
51
+ callback(err);
52
+ return;
53
+ }
54
+ tranformSvg(String(result), options, state, callback);
55
+ });
56
+ }
57
+ }
58
+ exports.default = svgrLoader;
@@ -0,0 +1,4 @@
1
+ import type { LoaderContext } from '../../compiled/webpack';
2
+ import { SwcOptions } from '../types';
3
+ declare function swcLoader(this: LoaderContext<SwcOptions>, contents: string): void;
4
+ export default swcLoader;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@swc/core");
4
+ const types_1 = require("../types");
5
+ function getBaseOpts({ filename }) {
6
+ const isTSFile = filename.endsWith('.ts');
7
+ const isTypeScript = isTSFile || filename.endsWith('.tsx');
8
+ const isDev = process.env.NODE_ENV === types_1.Env.development;
9
+ /**
10
+ * Not use swc auto polyfill , depend on `preset-umi/features/polyfill/polyfill` imported polyfill file
11
+ *
12
+ * @issue https://github.com/swc-project/swc/issues/2607
13
+ * https://github.com/swc-project/swc/issues/1604
14
+ */
15
+ const swcOpts = {
16
+ module: {
17
+ // @ts-ignore
18
+ type: 'es6',
19
+ ignoreDynamic: true,
20
+ },
21
+ jsc: {
22
+ parser: {
23
+ syntax: isTypeScript ? 'typescript' : 'ecmascript',
24
+ [isTypeScript ? 'tsx' : 'jsx']: !isTSFile,
25
+ dynamicImport: isTypeScript,
26
+ },
27
+ target: 'es2015',
28
+ transform: {
29
+ react: {
30
+ runtime: 'automatic',
31
+ pragma: 'React.createElement',
32
+ pragmaFrag: 'React.Fragment',
33
+ throwIfNamespace: true,
34
+ development: isDev,
35
+ useBuiltins: true,
36
+ },
37
+ },
38
+ },
39
+ };
40
+ return swcOpts;
41
+ }
42
+ function swcLoader(contents) {
43
+ // 启用异步模式
44
+ const callback = this.async();
45
+ const loaderOpts = this.getOptions();
46
+ const { sync = false, parseMap = false, ...otherOpts } = loaderOpts;
47
+ const filename = this.resourcePath;
48
+ const swcOpts = {
49
+ ...getBaseOpts({
50
+ filename,
51
+ }),
52
+ filename,
53
+ sourceMaps: this.sourceMap,
54
+ sourceFileName: filename,
55
+ ...otherOpts,
56
+ };
57
+ try {
58
+ if (sync) {
59
+ const output = (0, core_1.transformSync)(contents, swcOpts);
60
+ callback(null, output.code, parseMap ? JSON.parse(output.map) : output.map);
61
+ }
62
+ else {
63
+ (0, core_1.transform)(contents, swcOpts).then((output) => {
64
+ callback(null, output.code, parseMap ? JSON.parse(output.map) : output.map);
65
+ }, (err) => {
66
+ callback(err);
67
+ });
68
+ }
69
+ }
70
+ catch (e) {
71
+ callback(e);
72
+ }
73
+ }
74
+ exports.default = swcLoader;
@@ -0,0 +1,11 @@
1
+ import { Compilation, Compiler } from '@umijs/bundler-webpack/compiled/webpack';
2
+ interface IOpts {
3
+ sourcemap?: any;
4
+ }
5
+ declare class ESBuildCSSMinifyPlugin {
6
+ options: IOpts;
7
+ constructor(options?: IOpts);
8
+ apply(compiler: Compiler): void;
9
+ transformAssets(compilation: Compilation): Promise<void>;
10
+ }
11
+ export default ESBuildCSSMinifyPlugin;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
4
+ const webpack_sources_1 = require("@umijs/bundler-webpack/compiled/webpack-sources");
5
+ const version = require('../../package.json');
6
+ const PLUGIN_NAME = 'ESBuildCSSMinifyPlugin';
7
+ const RE_CSS_FILE = /\.css(\?.*)?$/i;
8
+ class ESBuildCSSMinifyPlugin {
9
+ constructor(options = {}) {
10
+ this.options = options;
11
+ }
12
+ apply(compiler) {
13
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
14
+ compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_, hash) => {
15
+ hash.update(JSON.stringify({
16
+ version,
17
+ options: this.options,
18
+ }));
19
+ });
20
+ compilation.hooks.processAssets.tapPromise({
21
+ name: PLUGIN_NAME,
22
+ stage: 400,
23
+ additionalAssets: true,
24
+ }, async () => {
25
+ await this.transformAssets(compilation);
26
+ });
27
+ });
28
+ }
29
+ async transformAssets(compilation) {
30
+ const { options: { devtool }, } = compilation.compiler;
31
+ const sourcemap = this.options.sourcemap === undefined ? !!devtool : this.options.sourcemap;
32
+ const assets = compilation.getAssets().filter((asset) => {
33
+ return !asset.info.minimized && RE_CSS_FILE.test(asset.name);
34
+ });
35
+ await Promise.all(assets.map(async (asset) => {
36
+ const { source, map } = asset.source.sourceAndMap();
37
+ const sourceAsString = source.toString();
38
+ const result = await (0, esbuild_1.transform)(sourceAsString, {
39
+ loader: 'css',
40
+ sourcemap,
41
+ sourcefile: asset.name,
42
+ minify: true,
43
+ });
44
+ compilation.updateAsset(asset.name,
45
+ // @ts-ignore
46
+ sourcemap
47
+ ? new webpack_sources_1.SourceMapSource(result.code, asset.name, result.map, sourceAsString, map, true)
48
+ : new webpack_sources_1.RawSource(result.code), { ...asset.info, minimized: true });
49
+ }));
50
+ }
51
+ }
52
+ exports.default = ESBuildCSSMinifyPlugin;
@@ -0,0 +1,10 @@
1
+ import type { TransformOptions } from '@parcel/css';
2
+ import type { Compiler } from '../../compiled/webpack/types';
3
+ declare type MinifyPluginOpts = Omit<TransformOptions, 'filename' | 'code' | 'minify'>;
4
+ export declare class ParcelCSSMinifyPlugin {
5
+ private readonly options;
6
+ constructor(opts?: MinifyPluginOpts);
7
+ apply(compiler: Compiler): void;
8
+ private transformAssets;
9
+ }
10
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParcelCSSMinifyPlugin = void 0;
4
+ const utils_1 = require("@umijs/utils");
5
+ const buffer_1 = require("buffer");
6
+ const path_1 = require("path");
7
+ const webpack_sources_1 = require("../../compiled/webpack-sources");
8
+ const pkgPath = (0, path_1.join)(__dirname, '../../package.json');
9
+ const pkg = require(pkgPath);
10
+ const PLUGIN_NAME = 'parcel-css-minify-plugin';
11
+ const CSS_FILE_REG = /\.css(?:\?.*)?$/i;
12
+ class ParcelCSSMinifyPlugin {
13
+ constructor(opts = {}) {
14
+ this.options = opts;
15
+ }
16
+ apply(compiler) {
17
+ const meta = JSON.stringify({
18
+ name: pkg.name,
19
+ version: pkg.version,
20
+ options: this.options,
21
+ });
22
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
23
+ compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_, hash) => hash.update(meta));
24
+ compilation.hooks.processAssets.tapPromise({
25
+ name: PLUGIN_NAME,
26
+ // @ts-ignore
27
+ stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
28
+ additionalAssets: true,
29
+ }, async () => await this.transformAssets(compilation));
30
+ compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (statsPrinter) => {
31
+ statsPrinter.hooks.print
32
+ .for('asset.info.minimized')
33
+ // @ts-ignore
34
+ .tap(PLUGIN_NAME, (minimized, { green, formatFlag }) => {
35
+ // @ts-ignore
36
+ return minimized ? green(formatFlag('minimized')) : undefined;
37
+ });
38
+ });
39
+ });
40
+ }
41
+ async transformAssets(compilation) {
42
+ const { options: { devtool }, } = compilation.compiler;
43
+ const sourcemap = this.options.sourceMap === undefined
44
+ ? (devtool && devtool.includes('source-map'))
45
+ : this.options.sourceMap;
46
+ const assets = compilation.getAssets().filter((asset) => {
47
+ return !asset.info.minimized && CSS_FILE_REG.test(asset.name);
48
+ });
49
+ await Promise.all(assets.map(async (asset) => {
50
+ const { source, map } = asset.source.sourceAndMap();
51
+ const sourceAsString = source.toString();
52
+ const code = typeof source === 'string' ? buffer_1.Buffer.from(source) : source;
53
+ const { transform } = (0, utils_1.importLazy)('@parcel/css');
54
+ const result = await transform({
55
+ filename: asset.name,
56
+ code,
57
+ minify: true,
58
+ sourceMap: sourcemap,
59
+ ...this.options,
60
+ });
61
+ const codeString = result.code.toString();
62
+ compilation.updateAsset(asset.name,
63
+ // @ts-ignore
64
+ sourcemap
65
+ ? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
66
+ : new webpack_sources_1.RawSource(codeString), {
67
+ ...asset.info,
68
+ minimized: true,
69
+ });
70
+ }));
71
+ }
72
+ }
73
+ exports.ParcelCSSMinifyPlugin = ParcelCSSMinifyPlugin;
@@ -0,0 +1,15 @@
1
+ import { Compiler, ProgressPlugin } from '@umijs/bundler-webpack/compiled/webpack';
2
+ interface IOpts {
3
+ name?: string;
4
+ }
5
+ declare class UmiProgressPlugin extends ProgressPlugin {
6
+ options: IOpts;
7
+ constructor(options?: IOpts);
8
+ apply(compiler: Compiler): void;
9
+ updateProgress(opts: {
10
+ percent: number;
11
+ message: string;
12
+ details: any[];
13
+ }): void;
14
+ }
15
+ export default UmiProgressPlugin;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
4
+ const utils_1 = require("@umijs/utils");
5
+ const PLUGIN_NAME = 'ProgressPlugin';
6
+ class UmiProgressPlugin extends webpack_1.ProgressPlugin {
7
+ constructor(options = {}) {
8
+ super({ activeModules: true });
9
+ this.options = options;
10
+ this.handler = (percent, message, ...details) => {
11
+ this.updateProgress({ percent, message, details });
12
+ };
13
+ }
14
+ apply(compiler) {
15
+ compiler.hooks.invalid.tap(PLUGIN_NAME, () => {
16
+ utils_1.logger.wait('Compiling...');
17
+ });
18
+ compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
19
+ const { errors, warnings } = stats.toJson({
20
+ all: false,
21
+ warnings: true,
22
+ errors: true,
23
+ colors: true,
24
+ });
25
+ const hasErrors = !!(errors === null || errors === void 0 ? void 0 : errors.length);
26
+ const hasWarnings = !!(warnings === null || warnings === void 0 ? void 0 : warnings.length);
27
+ hasWarnings;
28
+ if (hasErrors) {
29
+ errors.forEach((error) => {
30
+ utils_1.logger.error(`${error.moduleName}${error.loc ? `:${error.loc}` : ''}`);
31
+ console.log(error.message);
32
+ });
33
+ }
34
+ else {
35
+ const prefix = this.options.name ? `${this.options.name} ` : '';
36
+ utils_1.logger.event(`${prefix}Compiled successfully in ${stats.endTime - stats.startTime} ms (${stats.compilation.modules.size} modules)`);
37
+ }
38
+ });
39
+ }
40
+ updateProgress(opts) {
41
+ opts;
42
+ }
43
+ }
44
+ exports.default = UmiProgressPlugin;
@@ -0,0 +1,4 @@
1
+ import type { Compiler } from '@umijs/bundler-webpack/compiled/webpack';
2
+ export declare class RuntimePublicPathPlugin {
3
+ apply(compiler: Compiler): void;
4
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RuntimePublicPathPlugin = void 0;
4
+ const PLUGIN_NAME = 'RuntimePublicPath';
5
+ // ref: https://gist.github.com/ScriptedAlchemy/60d0c49ce049184f6ce3e86ca351fdca
6
+ class RuntimePublicPathPlugin {
7
+ apply(compiler) {
8
+ compiler.hooks.make.tap(PLUGIN_NAME, (compilation) => {
9
+ compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module) => {
10
+ // The hook to get the public path ('__webpack_require__.p')
11
+ // https://github.com/webpack/webpack/blob/master/lib/runtime/PublicPathRuntimeModule.js
12
+ if (module.constructor.name === 'PublicPathRuntimeModule') {
13
+ // @ts-ignore
14
+ module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath;`;
15
+ }
16
+ });
17
+ });
18
+ }
19
+ }
20
+ exports.RuntimePublicPathPlugin = RuntimePublicPathPlugin;
@@ -0,0 +1,9 @@
1
+ import { Compiler } from '@umijs/bundler-webpack/compiled/webpack';
2
+ interface IOpts {
3
+ }
4
+ declare class _SamplePlugin {
5
+ options: IOpts;
6
+ constructor(options?: IOpts);
7
+ apply(compiler: Compiler): void;
8
+ }
9
+ export default _SamplePlugin;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const PLUGIN_NAME = 'SamplePlugin';
4
+ class _SamplePlugin {
5
+ constructor(options = {}) {
6
+ this.options = options;
7
+ }
8
+ apply(compiler) {
9
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
10
+ compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_) => { });
11
+ });
12
+ }
13
+ }
14
+ exports.default = _SamplePlugin;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ // MIT: copy from https://github.com/vercel/next.js/blob/canary/packages/next/build/webpack/require-hook.ts
3
+ // sync injects a hook for webpack and webpack/... requires to use the internal ncc webpack version
4
+ // this is in order for userland plugins to attach to the same webpack instance as umi
5
+ // the individual compiled modules are as defined for the compilation in bundles/webpack/packages/*
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ // @ts-ignore
11
+ const deepImports_json_1 = __importDefault(require("@umijs/bundler-webpack/compiled/webpack/deepImports.json"));
12
+ const hookPropertyMap = new Map([
13
+ ['webpack', '@umijs/bundler-webpack/compiled/webpack'],
14
+ ['webpack/package', '@umijs/bundler-webpack/compiled/webpack/package'],
15
+ ['webpack/package.json', '@umijs/bundler-webpack/compiled/webpack/package'],
16
+ ['webpack/lib/webpack', '@umijs/bundler-webpack/compiled/webpack'],
17
+ ['webpack/lib/webpack.js', '@umijs/bundler-webpack/compiled/webpack'],
18
+ ]);
19
+ deepImports_json_1.default.forEach((item) => {
20
+ const name = item.split('/').pop();
21
+ hookPropertyMap.set(item, `@umijs/bundler-webpack/compiled/webpack/${name}`);
22
+ hookPropertyMap.set(`${item}.js`, `@umijs/bundler-webpack/compiled/webpack/${name}`);
23
+ });
24
+ const mod = require('module');
25
+ const resolveFilename = mod._resolveFilename;
26
+ mod._resolveFilename = function (request, parent, isMain, options) {
27
+ const hookResolved = hookPropertyMap.get(request);
28
+ if (hookResolved)
29
+ request = hookResolved;
30
+ return resolveFilename.call(mod, request, parent, isMain, options);
31
+ };
@@ -0,0 +1,3 @@
1
+ /// <reference types="hapi__joi" />
2
+ import type { Root } from '@hapi/joi';
3
+ export declare function getSchemas(): Record<string, (Joi: Root) => any>;