@shuvi/toolpack 0.0.1-rc.9 → 1.0.0-rc.10

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 (103) hide show
  1. package/lib/babel/plugins/auto-css-modules.js +1 -1
  2. package/lib/babel/plugins/{loadable-plugin.d.ts → dynamic-plugin.d.ts} +1 -1
  3. package/lib/babel/plugins/{loadable-plugin.js → dynamic-plugin.js} +9 -9
  4. package/lib/babel/plugins/optimize-hook-destructuring.d.ts +1 -1
  5. package/lib/babel/plugins/optimize-hook-destructuring.js +4 -4
  6. package/lib/babel/preset.js +25 -5
  7. package/lib/constants.d.ts +1 -0
  8. package/lib/constants.js +5 -1
  9. package/lib/utils/bundle-require.d.ts +33 -0
  10. package/lib/utils/bundle-require.js +143 -0
  11. package/lib/utils/forkTsCheckerWebpackPlugin.js +2 -1
  12. package/lib/utils/formatWebpackMessages.d.ts +18 -4
  13. package/lib/utils/formatWebpackMessages.js +17 -14
  14. package/lib/webpack/config/base.d.ts +17 -4
  15. package/lib/webpack/config/base.js +144 -99
  16. package/lib/webpack/config/browser.d.ts +3 -4
  17. package/lib/webpack/config/browser.js +132 -56
  18. package/lib/webpack/config/index.js +18 -7
  19. package/lib/webpack/config/node.d.ts +3 -4
  20. package/lib/webpack/config/node.js +21 -28
  21. package/lib/webpack/config/parts/external.d.ts +3 -2
  22. package/lib/webpack/config/parts/external.js +16 -10
  23. package/lib/webpack/config/parts/helpers.d.ts +3 -1
  24. package/lib/webpack/config/parts/helpers.js +14 -1
  25. package/lib/webpack/config/parts/resolve.js +1 -0
  26. package/lib/webpack/config/parts/style.d.ts +5 -2
  27. package/lib/webpack/config/parts/style.js +125 -60
  28. package/lib/webpack/dynamic-dll/bundler/index.d.ts +22 -0
  29. package/lib/webpack/dynamic-dll/bundler/index.js +211 -0
  30. package/lib/webpack/dynamic-dll/bundler/webpack-config.d.ts +16 -0
  31. package/lib/webpack/dynamic-dll/bundler/webpack-config.js +116 -0
  32. package/lib/webpack/dynamic-dll/constants.d.ts +6 -0
  33. package/lib/webpack/dynamic-dll/constants.js +9 -0
  34. package/lib/webpack/dynamic-dll/dep/getCJSExports.d.ts +3 -0
  35. package/lib/webpack/dynamic-dll/dep/getCJSExports.js +58 -0
  36. package/lib/webpack/dynamic-dll/dep/getExposeFromContent.d.ts +1 -0
  37. package/lib/webpack/dynamic-dll/dep/getExposeFromContent.js +80 -0
  38. package/lib/webpack/dynamic-dll/dep/getModuleExports.d.ts +7 -0
  39. package/lib/webpack/dynamic-dll/dep/getModuleExports.js +46 -0
  40. package/lib/webpack/dynamic-dll/dep/index.d.ts +13 -0
  41. package/lib/webpack/dynamic-dll/dep/index.js +43 -0
  42. package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.d.ts +1 -0
  43. package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.js +15 -0
  44. package/lib/webpack/dynamic-dll/index.d.ts +35 -0
  45. package/lib/webpack/dynamic-dll/index.js +198 -0
  46. package/lib/webpack/dynamic-dll/metadata.d.ts +13 -0
  47. package/lib/webpack/dynamic-dll/metadata.js +62 -0
  48. package/lib/webpack/dynamic-dll/moduleCollector.d.ts +28 -0
  49. package/lib/webpack/dynamic-dll/moduleCollector.js +64 -0
  50. package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.d.ts +24 -0
  51. package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.js +70 -0
  52. package/lib/webpack/dynamic-dll/utils.d.ts +6 -0
  53. package/lib/webpack/dynamic-dll/utils.js +29 -0
  54. package/lib/webpack/index.d.ts +15 -0
  55. package/lib/webpack/index.js +110 -0
  56. package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.d.ts +11 -0
  57. package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.js +40 -0
  58. package/lib/webpack/loaders/parcel-css-loader/index.d.ts +4 -0
  59. package/lib/webpack/loaders/parcel-css-loader/index.js +369 -0
  60. package/lib/webpack/loaders/parcel-css-loader/runtime/api.d.ts +2 -0
  61. package/lib/webpack/loaders/parcel-css-loader/runtime/api.js +85 -0
  62. package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.d.ts +2 -0
  63. package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.js +23 -0
  64. package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.d.ts +2 -0
  65. package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.js +2 -0
  66. package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.d.ts +2 -0
  67. package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.js +16 -0
  68. package/lib/webpack/loaders/parcel-css-loader/utils.d.ts +28 -0
  69. package/lib/webpack/loaders/parcel-css-loader/utils.js +869 -0
  70. package/lib/webpack/loaders/route-component-loader.js +25 -5
  71. package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.d.ts +94 -0
  72. package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.js +162 -0
  73. package/lib/webpack/loaders/shuvi-swc-loader/index.d.ts +2 -0
  74. package/lib/webpack/loaders/shuvi-swc-loader/index.js +119 -0
  75. package/lib/webpack/plugins/build-manifest-plugin.js +44 -23
  76. package/lib/webpack/plugins/dynamic-public-path-plugin.d.ts +9 -0
  77. package/lib/webpack/plugins/dynamic-public-path-plugin.js +50 -0
  78. package/lib/webpack/plugins/fix-watching-plugin.d.ts +4 -0
  79. package/lib/webpack/plugins/fix-watching-plugin.js +23 -0
  80. package/lib/webpack/plugins/jsconfig-paths-plugin.d.ts +44 -0
  81. package/lib/webpack/plugins/jsconfig-paths-plugin.js +228 -0
  82. package/lib/webpack/plugins/module-replace-plugin/index.js +5 -1
  83. package/lib/webpack/plugins/module-replace-plugin/plugin.d.ts +7 -6
  84. package/lib/webpack/plugins/module-replace-plugin/plugin.js +56 -33
  85. package/lib/webpack/plugins/module-replace-plugin/stub-loader.js +47 -7
  86. package/lib/webpack/plugins/require-cache-hot-reloader-plugin.js +9 -8
  87. package/lib/webpack/plugins/support-ts-extension-resolver-plugin.d.ts +4 -0
  88. package/lib/webpack/plugins/support-ts-extension-resolver-plugin.js +23 -0
  89. package/lib/webpack/types.d.ts +40 -0
  90. package/lib/webpack/types.js +2 -0
  91. package/package.json +46 -40
  92. package/lib/utils/emptyComponent.d.ts +0 -1
  93. package/lib/utils/emptyComponent.js +0 -7
  94. package/lib/utils/errorOverlayMiddleware.d.ts +0 -1
  95. package/lib/utils/errorOverlayMiddleware.js +0 -21
  96. package/lib/utils/hotDevClient/eventsource.d.ts +0 -1
  97. package/lib/utils/hotDevClient/eventsource.js +0 -63
  98. package/lib/utils/hotDevClient/index.d.ts +0 -4
  99. package/lib/utils/hotDevClient/index.js +0 -289
  100. package/lib/utils/verifyTypeScriptSetup.d.ts +0 -5
  101. package/lib/utils/verifyTypeScriptSetup.js +0 -229
  102. package/lib/webpack/loaders/export-global-loader.d.ts +0 -7
  103. package/lib/webpack/loaders/export-global-loader.js +0 -26
@@ -1,12 +1,32 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const loader_utils_1 = __importDefault(require("loader-utils"));
26
+ const loaderUtils = __importStar(require("loader-utils"));
7
27
  const routeComponentLoader = function () {
8
- const { componentAbsolutePath } = loader_utils_1.default.getOptions(this);
9
- const stringifyRequest = loader_utils_1.default.stringifyRequest(this, `${componentAbsolutePath}?__shuvi-route`);
28
+ const { componentAbsolutePath } = loaderUtils.getOptions(this);
29
+ const stringifyRequest = loaderUtils.stringifyRequest(this, `${componentAbsolutePath}?__shuvi-route`);
10
30
  return `
11
31
  const = require(${stringifyRequest})
12
32
  `.trim();
@@ -0,0 +1,94 @@
1
+ declare type Obj = Record<string, any>;
2
+ export declare type LoaderSWCOptions = {
3
+ filename: string;
4
+ isServer: boolean;
5
+ isPageFile: boolean;
6
+ development: boolean;
7
+ minify: boolean | Obj;
8
+ hasReactRefresh: boolean;
9
+ supportedBrowsers: any[];
10
+ experimental: Obj;
11
+ compiler: Obj;
12
+ swcCacheDir: string;
13
+ keep: string[];
14
+ };
15
+ export declare function getParserOptions({ filename, compiler, ...rest }: {
16
+ filename: string;
17
+ compiler: Obj;
18
+ }): {
19
+ syntax: string;
20
+ dynamicImport: boolean;
21
+ decorators: boolean;
22
+ importAssertions: boolean;
23
+ };
24
+ export default function getLoaderSWCOptions({ filename, development, isServer, minify, isPageFile, hasReactRefresh, experimental, compiler, supportedBrowsers, swcCacheDir, keep }: LoaderSWCOptions): {
25
+ jsc: {
26
+ externalHelpers: boolean;
27
+ parser: {
28
+ syntax: string;
29
+ dynamicImport: boolean;
30
+ decorators: boolean;
31
+ importAssertions: boolean;
32
+ };
33
+ experimental: {
34
+ keepImportAssertions: boolean;
35
+ plugins: any;
36
+ cacheRoot: string;
37
+ };
38
+ transform: {
39
+ legacyDecorator: boolean;
40
+ decoratorMetadata: boolean;
41
+ useDefineForClassFields: boolean;
42
+ react: {
43
+ importSource: any;
44
+ runtime: string;
45
+ pragma: string;
46
+ pragmaFrag: string;
47
+ throwIfNamespace: boolean;
48
+ development: boolean;
49
+ useBuiltins: boolean;
50
+ refresh: boolean;
51
+ };
52
+ optimizer: {
53
+ simplify: boolean;
54
+ globals: {
55
+ typeofs: {
56
+ window: string;
57
+ };
58
+ envs: {
59
+ NODE_ENV: string;
60
+ };
61
+ };
62
+ };
63
+ regenerator: {
64
+ importPath: string;
65
+ };
66
+ };
67
+ };
68
+ minify: boolean | Obj;
69
+ isDevelopment: boolean;
70
+ isServer: boolean;
71
+ isPageFile: boolean;
72
+ shakeExports: {
73
+ ignore: string[];
74
+ } | null;
75
+ disableShuviDynamic: any;
76
+ cssModuleFlag: string;
77
+ sourceMaps: undefined;
78
+ styledComponents: any;
79
+ removeConsole: any;
80
+ reactRemoveProperties: any;
81
+ modularizeImports: any;
82
+ emotion: {
83
+ enabled: boolean;
84
+ autoLabel: boolean;
85
+ sourcemap: boolean;
86
+ labelFormat?: undefined;
87
+ } | {
88
+ enabled: boolean;
89
+ autoLabel: boolean;
90
+ labelFormat: any;
91
+ sourcemap: any;
92
+ } | null;
93
+ };
94
+ export {};
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.getParserOptions = void 0;
15
+ function getParserOptions(_a) {
16
+ var { filename, compiler } = _a, rest = __rest(_a, ["filename", "compiler"]);
17
+ const isTSFile = filename.endsWith('.ts');
18
+ const isTypeScript = isTSFile || filename.endsWith('.tsx');
19
+ const enableDecorators = Boolean(compiler === null || compiler === void 0 ? void 0 : compiler.experimentalDecorators);
20
+ return Object.assign(Object.assign({}, rest), { syntax: isTypeScript ? 'typescript' : 'ecmascript', dynamicImport: true, decorators: enableDecorators,
21
+ // Exclude regular TypeScript files from React transformation to prevent e.g. generic parameters and angle-bracket type assertion from being interpreted as JSX tags.
22
+ [isTypeScript ? 'tsx' : 'jsx']: !isTSFile, importAssertions: true });
23
+ }
24
+ exports.getParserOptions = getParserOptions;
25
+ function getBaseSWCOptions({ filename, isPageFile, minify, development, hasReactRefresh, isServer, experimental, compiler, swcCacheDir, keep }) {
26
+ var _a, _b;
27
+ const parserConfig = getParserOptions({ filename, compiler });
28
+ const enableDecorators = Boolean(compiler === null || compiler === void 0 ? void 0 : compiler.experimentalDecorators);
29
+ const emitDecoratorMetadata = Boolean(compiler === null || compiler === void 0 ? void 0 : compiler.emitDecoratorMetadata);
30
+ const useDefineForClassFields = Boolean(compiler === null || compiler === void 0 ? void 0 : compiler.useDefineForClassFields);
31
+ const plugins = ((_a = experimental === null || experimental === void 0 ? void 0 : experimental.swcPlugins) !== null && _a !== void 0 ? _a : [])
32
+ .filter(Array.isArray)
33
+ .map(([name, options]) => [require.resolve(name), options]);
34
+ return {
35
+ jsc: {
36
+ externalHelpers: true,
37
+ parser: parserConfig,
38
+ experimental: {
39
+ keepImportAssertions: true,
40
+ plugins,
41
+ cacheRoot: swcCacheDir
42
+ },
43
+ transform: {
44
+ legacyDecorator: enableDecorators,
45
+ decoratorMetadata: emitDecoratorMetadata,
46
+ useDefineForClassFields: useDefineForClassFields,
47
+ react: {
48
+ importSource: (_b = compiler === null || compiler === void 0 ? void 0 : compiler.jsxImportSource) !== null && _b !== void 0 ? _b : ((compiler === null || compiler === void 0 ? void 0 : compiler.emotion) ? '@emotion/react' : 'react'),
49
+ runtime: 'automatic',
50
+ pragma: 'React.createElement',
51
+ pragmaFrag: 'React.Fragment',
52
+ throwIfNamespace: true,
53
+ development: !!development,
54
+ useBuiltins: true,
55
+ refresh: !!hasReactRefresh
56
+ },
57
+ optimizer: {
58
+ simplify: false,
59
+ globals: {
60
+ typeofs: {
61
+ window: isServer ? 'undefined' : 'object'
62
+ },
63
+ envs: {
64
+ NODE_ENV: development ? '"development"' : '"production"'
65
+ }
66
+ // TODO: handle process.browser to match babel replacing as well
67
+ }
68
+ },
69
+ regenerator: {
70
+ importPath: require.resolve('regenerator-runtime')
71
+ }
72
+ }
73
+ },
74
+ minify,
75
+ isDevelopment: development,
76
+ isServer,
77
+ isPageFile,
78
+ shakeExports: keep.length > 0 ? { ignore: keep } : null,
79
+ disableShuviDynamic: (compiler === null || compiler === void 0 ? void 0 : compiler.disableShuviDynamic) || false,
80
+ cssModuleFlag: 'cssmodules',
81
+ sourceMaps: undefined,
82
+ styledComponents: getStyledComponentsOptions(compiler, development),
83
+ removeConsole: compiler === null || compiler === void 0 ? void 0 : compiler.removeConsole,
84
+ reactRemoveProperties: compiler === null || compiler === void 0 ? void 0 : compiler.reactRemoveProperties,
85
+ modularizeImports: experimental === null || experimental === void 0 ? void 0 : experimental.modularizeImports,
86
+ emotion: getEmotionOptions(compiler, development)
87
+ };
88
+ }
89
+ function getStyledComponentsOptions(compiler, development) {
90
+ var _a;
91
+ let styledComponentsOptions = compiler === null || compiler === void 0 ? void 0 : compiler.styledComponents;
92
+ if (!styledComponentsOptions) {
93
+ return null;
94
+ }
95
+ return Object.assign(Object.assign({}, styledComponentsOptions), { displayName: (_a = styledComponentsOptions.displayName) !== null && _a !== void 0 ? _a : Boolean(development) });
96
+ }
97
+ function getEmotionOptions(compiler, development) {
98
+ var _a;
99
+ const emotion = compiler === null || compiler === void 0 ? void 0 : compiler.emotion;
100
+ if (!emotion) {
101
+ return null;
102
+ }
103
+ // default 'dev-only'
104
+ let autoLabel = !!development;
105
+ if (emotion === true) {
106
+ return {
107
+ enabled: true,
108
+ autoLabel,
109
+ sourcemap: autoLabel
110
+ };
111
+ }
112
+ switch (emotion.autoLabel) {
113
+ case 'never':
114
+ autoLabel = false;
115
+ break;
116
+ case 'always':
117
+ autoLabel = true;
118
+ break;
119
+ default:
120
+ break;
121
+ }
122
+ return {
123
+ enabled: true,
124
+ autoLabel,
125
+ labelFormat: emotion.labelFormat,
126
+ sourcemap: development ? (_a = emotion.sourceMap) !== null && _a !== void 0 ? _a : true : false
127
+ };
128
+ }
129
+ function getLoaderSWCOptions({ filename, development, isServer, minify, isPageFile, hasReactRefresh, experimental, compiler, supportedBrowsers, swcCacheDir, keep }) {
130
+ let baseOptions = getBaseSWCOptions({
131
+ filename,
132
+ isPageFile,
133
+ development,
134
+ isServer,
135
+ minify,
136
+ hasReactRefresh,
137
+ experimental,
138
+ compiler,
139
+ swcCacheDir,
140
+ keep
141
+ });
142
+ if (isServer) {
143
+ baseOptions.env = {
144
+ targets: {
145
+ // Targets the current version of Node.js
146
+ node: process.versions.node
147
+ }
148
+ };
149
+ }
150
+ else {
151
+ // Matches default @babel/preset-env behavior
152
+ baseOptions.jsc.target =
153
+ 'es5';
154
+ if (supportedBrowsers && supportedBrowsers.length > 0) {
155
+ baseOptions.env = {
156
+ targets: supportedBrowsers
157
+ };
158
+ }
159
+ }
160
+ return baseOptions;
161
+ }
162
+ exports.default = getLoaderSWCOptions;
@@ -0,0 +1,2 @@
1
+ export default function swcLoader(inputSource: any, inputSourceMap: any): void;
2
+ export const raw: true;
@@ -0,0 +1,119 @@
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.raw = void 0;
16
+ /*
17
+ Copyright (c) 2017 The swc Project Developers
18
+
19
+ Permission is hereby granted, free of charge, to any
20
+ person obtaining a copy of this software and associated
21
+ documentation files (the "Software"), to deal in the
22
+ Software without restriction, including without
23
+ limitation the rights to use, copy, modify, merge,
24
+ publish, distribute, sublicense, and/or sell copies of
25
+ the Software, and to permit persons to whom the Software
26
+ is furnished to do so, subject to the following
27
+ conditions:
28
+
29
+ The above copyright notice and this permission notice
30
+ shall be included in all copies or substantial portions
31
+ of the Software.
32
+
33
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
34
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
35
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
36
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
37
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
38
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
40
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
41
+ DEALINGS IN THE SOFTWARE.
42
+ */
43
+ const querystring_1 = __importDefault(require("querystring"));
44
+ const constants_1 = require("@shuvi/shared/lib/constants");
45
+ const escapeRegExp_1 = require("@shuvi/utils/lib/escapeRegExp");
46
+ const compiler_1 = require("@shuvi/compiler");
47
+ const getLoaderSWCOptions_1 = __importDefault(require("./getLoaderSWCOptions"));
48
+ const IS_PAGE_FILE = RegExp((0, escapeRegExp_1.escapeRegExp)(`?${constants_1.ROUTE_RESOURCE_QUERYSTRING}`));
49
+ function loaderTransform(source, inputSourceMap) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ // Make the loader async
52
+ const filename = this.resourcePath;
53
+ let loaderOptions = this.getOptions() || {};
54
+ const { isServer, experimental, compiler, supportedBrowsers, swcCacheDir, hasReactRefresh, minify = false } = loaderOptions;
55
+ const isPageFile = !!(this.resourceQuery && IS_PAGE_FILE.test(this.resourceQuery));
56
+ let keep = [];
57
+ if (isPageFile) {
58
+ const query = querystring_1.default.parse(this.resourceQuery.slice(1));
59
+ if (query.keep) {
60
+ if (Array.isArray(query.keep)) {
61
+ keep = query.keep;
62
+ }
63
+ else {
64
+ keep.push(query.keep);
65
+ }
66
+ }
67
+ }
68
+ const isDevelopment = this.mode === 'development';
69
+ const swcOptions = (0, getLoaderSWCOptions_1.default)({
70
+ filename,
71
+ isServer,
72
+ isPageFile,
73
+ minify,
74
+ development: this.mode === 'development',
75
+ hasReactRefresh: hasReactRefresh !== undefined
76
+ ? hasReactRefresh
77
+ : isDevelopment && !isServer,
78
+ experimental,
79
+ compiler,
80
+ supportedBrowsers,
81
+ swcCacheDir,
82
+ keep
83
+ });
84
+ const programmaticOptions = Object.assign(Object.assign({}, swcOptions), { filename, inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,
85
+ // Set the default sourcemap behavior based on Webpack's mapping flag,
86
+ sourceMaps: this.sourceMap, inlineSourcesContent: this.sourceMap,
87
+ // Ensure that Webpack will get a full absolute path in the sourcemap
88
+ // so that it can properly map the module back to its internal cached
89
+ // modules.
90
+ sourceFileName: filename });
91
+ if (!programmaticOptions.inputSourceMap) {
92
+ delete programmaticOptions.inputSourceMap;
93
+ }
94
+ // auto detect development mode
95
+ if (this.mode &&
96
+ programmaticOptions.jsc &&
97
+ programmaticOptions.jsc.transform &&
98
+ programmaticOptions.jsc.transform.react &&
99
+ !Object.prototype.hasOwnProperty.call(programmaticOptions.jsc.transform.react, 'development')) {
100
+ programmaticOptions.jsc.transform.react.development =
101
+ this.mode === 'development';
102
+ }
103
+ return (0, compiler_1.transform)(source, programmaticOptions).then(output => {
104
+ return [output.code, output.map ? JSON.parse(output.map) : undefined];
105
+ });
106
+ });
107
+ }
108
+ function swcLoader(inputSource, inputSourceMap) {
109
+ const callback = this.async && this.async();
110
+ loaderTransform.call(this, inputSource, inputSourceMap).then(([transformedSource, outputSourceMap]) => {
111
+ callback &&
112
+ callback(null, transformedSource, outputSourceMap || inputSourceMap);
113
+ }, err => {
114
+ callback && callback(err);
115
+ });
116
+ }
117
+ exports.default = swcLoader;
118
+ // accept Buffers instead of strings
119
+ exports.raw = true;
@@ -45,11 +45,23 @@ class BuildManifestPlugin {
45
45
  chunkRequest: {},
46
46
  loadble: {}
47
47
  });
48
+ const chunkRootModulesMap = new Map();
49
+ compilation.chunks.forEach(chunk => {
50
+ const { chunkGraph } = compilation;
51
+ if (chunkGraph) {
52
+ chunkGraph.getChunkRootModules(chunk).forEach(module => {
53
+ const id = chunkGraph.getModuleId(module);
54
+ if (id !== '') {
55
+ chunkRootModulesMap.set(id, true);
56
+ }
57
+ });
58
+ }
59
+ });
48
60
  compilation.chunkGroups.forEach(chunkGroup => {
49
61
  if (chunkGroup instanceof Entrypoint_1.default) {
50
62
  this._collectEntries(chunkGroup);
51
63
  }
52
- this._collect(chunkGroup, compiler, compilation);
64
+ this._collect(chunkGroup, compiler, compilation, chunkRootModulesMap);
53
65
  });
54
66
  this._manifest.loadble = Object.keys(this._manifest.loadble)
55
67
  .sort()
@@ -82,11 +94,11 @@ class BuildManifestPlugin {
82
94
  }
83
95
  }
84
96
  }
85
- _collect(chunkGroup, compiler, compilation) {
97
+ _collect(chunkGroup, compiler, compilation, chunkRootModulesMap) {
86
98
  const collectModules = this._options.modules;
87
99
  chunkGroup.origins.forEach(chunkGroupOrigin => {
88
100
  const { request } = chunkGroupOrigin;
89
- const ctx = { request, compiler, compilation };
101
+ const ctx = { request, compiler, compilation, chunkRootModulesMap };
90
102
  chunkGroup.chunks.forEach(chunk => {
91
103
  this._collectChunk(chunk, ctx);
92
104
  if (collectModules) {
@@ -120,7 +132,7 @@ class BuildManifestPlugin {
120
132
  }
121
133
  }
122
134
  }
123
- _collectChunkModule(chunk, { request, compiler, compilation }) {
135
+ _collectChunkModule(chunk, { request, compiler, compilation, chunkRootModulesMap }) {
124
136
  if (chunk.canBeInitial()) {
125
137
  return;
126
138
  }
@@ -132,21 +144,26 @@ class BuildManifestPlugin {
132
144
  this._pushLoadableModules(request, file);
133
145
  }
134
146
  });
135
- for (const module of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
136
- let id = compilation.chunkGraph.getModuleId(module);
137
- if (!module.type.startsWith('javascript')) {
138
- continue;
139
- }
140
- let name = typeof module.libIdent === 'function'
141
- ? module.libIdent({ context })
142
- : null;
143
- if (!name || name.endsWith('.css')) {
144
- continue;
147
+ const { chunkGraph } = compilation;
148
+ if (chunkGraph) {
149
+ for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
150
+ let id = chunkGraph.getModuleId(module);
151
+ if (!module.type.startsWith('javascript')) {
152
+ continue;
153
+ }
154
+ let name = typeof module.libIdent === 'function'
155
+ ? module.libIdent({ context })
156
+ : null;
157
+ if (!name || name.endsWith('.css')) {
158
+ continue;
159
+ }
160
+ if (chunkRootModulesMap.has(id)) {
161
+ this._pushLoadableModules(request, {
162
+ id,
163
+ name
164
+ });
165
+ }
145
166
  }
146
- this._pushLoadableModules(request, {
147
- id,
148
- name
149
- });
150
167
  }
151
168
  }
152
169
  _pushEntries(name, ext, value) {
@@ -182,12 +199,16 @@ class BuildManifestPlugin {
182
199
  };
183
200
  }
184
201
  if (typeof value === 'string') {
185
- modules[request].files.push(value);
202
+ const existed = modules[request].files.some(file => file === value);
203
+ if (!existed) {
204
+ modules[request].files.push(value);
205
+ }
186
206
  }
187
- else if (
188
- // Avoid duplicate files
189
- !modules[request].children.some(item => item.id === module.id)) {
190
- modules[request].children.push(value);
207
+ else {
208
+ const existed = modules[request].children.some(item => item.id === value.id);
209
+ if (!existed) {
210
+ modules[request].children.push(value);
211
+ }
191
212
  }
192
213
  }
193
214
  }
@@ -0,0 +1,9 @@
1
+ import { Compiler, Plugin } from 'webpack';
2
+ export default class DynamicPublicPathPlugin implements Plugin {
3
+ /**
4
+ * Apply the plugin
5
+ * @param {Compiler} compiler the compiler instance
6
+ * @returns {void}
7
+ */
8
+ apply(compiler: Compiler): void;
9
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const webpack_1 = require("webpack");
4
+ const constants_1 = require("@shuvi/shared/lib/constants");
5
+ const GLOBALTHIS = 'globalThis';
6
+ /**
7
+ * blog: use webpack build for production, just define __webpack_public_path__ to change asset url to quick release, without build again
8
+ *
9
+ * user define __webpack_public_path__, when async chunk entry contain __webpack_public_path__
10
+ *
11
+ * on client side, when load the async chunk, the source url is still webpack runtime __webpack_require__.p,
12
+ * after chunk loaded, runtime publicPath will change to __webpack_public_path__.
13
+ *
14
+ * on server side, first html is from server, the source path is from __webpack_require__.p,
15
+ * eg: <img src=__webpack_require__.p +xx.png />
16
+ *
17
+ * expect: when load async chunk, __webpack_require__.p is can be redefine by user
18
+ *
19
+ */
20
+ const PLUGINNAME = 'DynamicPublicPath';
21
+ class DynamicPublicPathPlugin {
22
+ /**
23
+ * Apply the plugin
24
+ * @param {Compiler} compiler the compiler instance
25
+ * @returns {void}
26
+ */
27
+ apply(compiler) {
28
+ compiler.hooks.compilation.tap(PLUGINNAME, compilation => {
29
+ compilation.hooks.runtimeRequirementInTree
30
+ .for(webpack_1.RuntimeGlobals.publicPath)
31
+ .tap(PLUGINNAME, chunk => {
32
+ compilation.addRuntimeModule(chunk, new DynamicPublicPath(PLUGINNAME));
33
+ });
34
+ });
35
+ }
36
+ }
37
+ exports.default = DynamicPublicPathPlugin;
38
+ class DynamicPublicPath extends webpack_1.RuntimeModule {
39
+ constructor(name) {
40
+ super(name, webpack_1.RuntimeModule.STAGE_ATTACH);
41
+ }
42
+ generate() {
43
+ return `
44
+ // server runtime public path
45
+ if (${GLOBALTHIS}["${constants_1.IDENTITY_RUNTIME_PUBLICPATH}"]) {
46
+ ${webpack_1.RuntimeGlobals.publicPath} = ${GLOBALTHIS}["${constants_1.IDENTITY_RUNTIME_PUBLICPATH}"];
47
+ }
48
+ `;
49
+ }
50
+ }
@@ -0,0 +1,4 @@
1
+ import { Compiler, Plugin } from 'webpack';
2
+ export default class FixWatchingPlugin implements Plugin {
3
+ apply(compiler: Compiler): void;
4
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const TIME_FIX = 5000;
4
+ const PLUGIN_NAME = 'fix-watching-plugin';
5
+ class FixWatchingPlugin {
6
+ apply(compiler) {
7
+ let watching;
8
+ let restored = false;
9
+ const aspectWatch = compiler.watch;
10
+ compiler.watch = function (...args) {
11
+ watching = aspectWatch.apply(compiler, args);
12
+ watching.startTime += TIME_FIX;
13
+ return watching;
14
+ };
15
+ compiler.hooks.done.tap(PLUGIN_NAME, stats => {
16
+ if (watching && !restored) {
17
+ stats.compilation.startTime -= TIME_FIX;
18
+ restored = true;
19
+ }
20
+ });
21
+ }
22
+ }
23
+ exports.default = FixWatchingPlugin;
@@ -0,0 +1,44 @@
1
+ import { ResolvePluginInstance, Resolver } from 'webpack';
2
+ export interface Pattern {
3
+ prefix: string;
4
+ suffix: string;
5
+ }
6
+ export declare function hasZeroOrOneAsteriskCharacter(str: string): boolean;
7
+ /**
8
+ * Determines whether a path starts with a relative path component (i.e. `.` or `..`).
9
+ */
10
+ export declare function pathIsRelative(testPath: string): boolean;
11
+ export declare function tryParsePattern(pattern: string): Pattern | undefined;
12
+ /** Return the object corresponding to the best pattern to match `candidate`. */
13
+ export declare function findBestPatternMatch<T>(values: readonly T[], getPattern: (value: T) => Pattern, candidate: string): T | undefined;
14
+ /**
15
+ * patternStrings contains both pattern strings (containing "*") and regular strings.
16
+ * Return an exact match if possible, or a pattern match, or undefined.
17
+ * (These are verified by verifyCompilerOptions to have 0 or 1 "*" characters.)
18
+ */
19
+ export declare function matchPatternOrExact(patternStrings: readonly string[], candidate: string): string | Pattern | undefined;
20
+ /**
21
+ * Tests whether a value is string
22
+ */
23
+ export declare function isString(text: unknown): text is string;
24
+ /**
25
+ * Given that candidate matches pattern, returns the text matching the '*'.
26
+ * E.g.: matchedText(tryParsePattern("foo*baz"), "foobarbaz") === "bar"
27
+ */
28
+ export declare function matchedText(pattern: Pattern, candidate: string): string;
29
+ export declare function patternText({ prefix, suffix }: Pattern): string;
30
+ declare type Paths = {
31
+ [match: string]: string[];
32
+ };
33
+ /**
34
+ * Handles tsconfig.json or jsconfig.js "paths" option for webpack
35
+ * Largely based on how the TypeScript compiler handles it:
36
+ * https://github.com/microsoft/TypeScript/blob/1a9c8197fffe3dace5f8dca6633d450a88cba66d/src/compiler/moduleNameResolver.ts#L1362
37
+ */
38
+ export default class JsConfigPathsPlugin implements ResolvePluginInstance {
39
+ paths: Paths;
40
+ resolvedBaseUrl: string;
41
+ constructor(paths: Paths, resolvedBaseUrl: string);
42
+ apply(resolver: Resolver): void;
43
+ }
44
+ export {};