@shuvi/toolpack 1.0.0-rc.0 → 1.0.0-rc.11
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.
- package/lib/babel/plugins/{loadable-plugin.d.ts → dynamic-plugin.d.ts} +1 -1
- package/lib/babel/plugins/{loadable-plugin.js → dynamic-plugin.js} +8 -8
- package/lib/babel/preset.js +1 -1
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +2 -1
- package/lib/utils/formatWebpackMessages.d.ts +18 -4
- package/lib/utils/formatWebpackMessages.js +15 -13
- package/lib/webpack/config/base.d.ts +3 -1
- package/lib/webpack/config/base.js +43 -22
- package/lib/webpack/config/browser.js +47 -31
- package/lib/webpack/config/node.js +3 -3
- package/lib/webpack/config/parts/helpers.d.ts +1 -0
- package/lib/webpack/config/parts/helpers.js +8 -1
- package/lib/webpack/dynamic-dll/bundler/webpack-config.js +1 -1
- package/lib/webpack/dynamic-dll/index.d.ts +2 -2
- package/lib/webpack/dynamic-dll/index.js +26 -26
- package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.js +0 -1
- package/lib/webpack/index.d.ts +3 -5
- package/lib/webpack/index.js +4 -6
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.d.ts +9 -2
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.js +2 -1
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.d.ts +94 -0
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.js +162 -0
- package/lib/webpack/loaders/{shuvi-swc-loader.d.ts → shuvi-swc-loader/index.d.ts} +0 -0
- package/lib/webpack/loaders/{shuvi-swc-loader.js → shuvi-swc-loader/index.js} +50 -86
- package/lib/webpack/plugins/dynamic-public-path-plugin.js +3 -2
- package/lib/webpack/plugins/module-replace-plugin/plugin.d.ts +1 -0
- package/lib/webpack/plugins/module-replace-plugin/plugin.js +9 -1
- package/package.json +16 -50
- package/lib/swc/tests/fixture/auto-css-module/no-flag/input.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/no-flag/input.js +0 -4
- package/lib/swc/tests/fixture/auto-css-module/no-flag/output.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/no-flag/output.js +0 -4
- package/lib/swc/tests/fixture/auto-css-module/with-flag/input.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/with-flag/input.js +0 -2
- package/lib/swc/tests/fixture/auto-css-module/with-flag/output.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/with-flag/output.js +0 -2
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/input.js +0 -5
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/output.js +0 -11
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/input.js +0 -9
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/output.js +0 -12
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/output.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/output.js +0 -8
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/input.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/output.js +0 -9
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/input.js +0 -5
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/output.js +0 -11
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/input.js +0 -9
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/output.js +0 -12
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/output.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/output.js +0 -8
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/input.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/output.js +0 -9
- package/lib/swc/tests/full/auto-cjs/1/input.d.ts +0 -1
- package/lib/swc/tests/full/auto-cjs/1/input.js +0 -8
- package/lib/swc/tests/full/auto-cjs/1/output.d.ts +0 -1
- package/lib/swc/tests/full/auto-cjs/1/output.js +0 -8
- package/lib/utils/build-loaders.d.ts +0 -2
- package/lib/utils/build-loaders.js +0 -131
- package/lib/utils/hotDevClient/eventsource.d.ts +0 -1
- package/lib/utils/hotDevClient/eventsource.js +0 -64
- package/lib/utils/hotDevClient/index.d.ts +0 -4
- package/lib/utils/hotDevClient/index.js +0 -362
- package/lib/utils/load-sources.d.ts +0 -3
- package/lib/utils/load-sources.js +0 -94
- package/swc-source/native/shuvi-swc.darwin-arm64.node +0 -0
package/lib/webpack/index.js
CHANGED
|
@@ -3,13 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DllPlugin = exports.Dependency = exports.DelegatedPlugin = exports.DefinePlugin = exports.ContextReplacementPlugin = exports.ContextExclusionPlugin = exports.ConcatenationScope = exports.Compiler = exports.Compilation = exports.CleanPlugin = exports.ChunkGraph = exports.Chunk = exports.Cache = exports.BannerPlugin = exports.AsyncDependenciesBlock = exports.AutomaticPrefetchPlugin = exports.experiments = exports.sources = exports.util = exports.debug = exports.sharing = exports.container = exports.library = exports.wasm = exports.electron = exports.node = exports.webworker = exports.web = exports.prefetch = exports.runtime = exports.optimize = exports.javascript = exports.ids = exports.dependencies = exports.config = exports.cache = exports.ValidationError = exports.WebpackOptionsValidationError = exports.UsageState = exports.RuntimeGlobals = exports.ModuleFilenameHelpers = exports.cli = exports.version = exports.validateSchema = exports.validate = exports.webpack = exports.DynamicDll = exports.WebpackChain = exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.DllReferencePlugin = exports.DllPlugin = exports.Dependency = exports.DelegatedPlugin = exports.DefinePlugin = exports.ContextReplacementPlugin = exports.ContextExclusionPlugin = exports.ConcatenationScope = exports.Compiler = exports.Compilation = exports.CleanPlugin = exports.ChunkGraph = exports.Chunk = exports.Cache = exports.BannerPlugin = exports.AsyncDependenciesBlock = exports.AutomaticPrefetchPlugin = exports.experiments = exports.sources = exports.util = exports.debug = exports.sharing = exports.container = exports.library = exports.wasm = exports.electron = exports.node = exports.webworker = exports.web = exports.prefetch = exports.runtime = exports.optimize = exports.javascript = exports.ids = exports.dependencies = exports.config = exports.cache = exports.ValidationError = exports.WebpackOptionsValidationError = exports.UsageState = exports.RuntimeGlobals = exports.ModuleFilenameHelpers = exports.cli = exports.version = exports.validateSchema = exports.validate = exports.webpack = exports.DynamicDll = exports.WebpackChain = exports.default = void 0;
|
|
7
|
+
exports.webpackResolveContext = exports.Watching = exports.MultiStats = exports.WebpackOptionsDefaulter = exports.WebpackOptionsApply = exports.WebpackError = exports.WatchIgnorePlugin = exports.Template = exports.Stats = exports.SourceMapDevToolPlugin = exports.SingleEntryPlugin = exports.RuntimeModule = exports.ProvidePlugin = exports.ProgressPlugin = exports.PrefetchPlugin = exports.Parser = exports.MultiCompiler = exports.NormalModuleReplacementPlugin = exports.NormalModule = exports.NoEmitOnErrorsPlugin = exports.ModuleGraphConnection = exports.ModuleGraph = exports.Module = exports.LoaderTargetPlugin = exports.LoaderOptionsPlugin = exports.LibraryTemplatePlugin = exports.LibManifestPlugin = exports.JavascriptModulesPlugin = exports.IgnorePlugin = exports.HotModuleReplacementPlugin = exports.HotUpdateChunk = exports.Generator = exports.ExternalsPlugin = exports.ExternalModule = exports.EvalSourceMapDevToolPlugin = exports.EvalDevToolModulePlugin = exports.EnvironmentPlugin = exports.EntryPlugin = exports.EntryOptionPlugin = exports.DynamicEntryPlugin = void 0;
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const webpack_1 = __importDefault(require("webpack"));
|
|
10
10
|
exports.default = webpack_1.default;
|
|
11
|
-
const webpack_dev_middleware_1 = __importDefault(require("webpack-dev-middleware"));
|
|
12
|
-
exports.WebpackDevMiddleware = webpack_dev_middleware_1.default;
|
|
13
11
|
var config_1 = require("./config");
|
|
14
12
|
Object.defineProperty(exports, "WebpackChain", { enumerable: true, get: function () { return config_1.WebpackChain; } });
|
|
15
13
|
var dynamic_dll_1 = require("./dynamic-dll");
|
|
@@ -108,5 +106,5 @@ Object.defineProperty(exports, "Watching", { enumerable: true, get: function ()
|
|
|
108
106
|
/**
|
|
109
107
|
* resolve webpack module for not shuvi plugin
|
|
110
108
|
*/
|
|
111
|
-
const
|
|
112
|
-
exports.
|
|
109
|
+
const webpackResolveContext = (0, path_1.join)((0, path_1.dirname)(require.resolve('webpack/package.json')), '../');
|
|
110
|
+
exports.webpackResolveContext = webpackResolveContext;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
export interface ICssSyntaxError {
|
|
2
|
+
source: string;
|
|
3
|
+
fileName: string;
|
|
4
|
+
loc: {
|
|
5
|
+
line: number;
|
|
6
|
+
column: number;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
1
9
|
export default class CssSyntaxError extends Error {
|
|
2
|
-
constructor(error:
|
|
3
|
-
stack: boolean;
|
|
10
|
+
constructor(error: ICssSyntaxError);
|
|
4
11
|
}
|
|
@@ -23,7 +23,7 @@ function showSourceCode(source, lineNo, columnNo) {
|
|
|
23
23
|
}
|
|
24
24
|
class CssSyntaxError extends Error {
|
|
25
25
|
constructor(error) {
|
|
26
|
-
super(
|
|
26
|
+
super();
|
|
27
27
|
const { source, fileName, loc } = error;
|
|
28
28
|
const { line, column } = loc;
|
|
29
29
|
this.message = `\n\n${this.message}\n\n`;
|
|
@@ -33,6 +33,7 @@ class CssSyntaxError extends Error {
|
|
|
33
33
|
}
|
|
34
34
|
this.message += `\n${showSourceCode(source, line, column)}\n`;
|
|
35
35
|
// We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
|
|
36
|
+
// @ts-ignore
|
|
36
37
|
this.stack = false;
|
|
37
38
|
}
|
|
38
39
|
}
|
|
@@ -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;
|
|
File without changes
|
|
@@ -1,4 +1,18 @@
|
|
|
1
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;
|
|
2
16
|
/*
|
|
3
17
|
Copyright (c) 2017 The swc Project Developers
|
|
4
18
|
|
|
@@ -26,96 +40,46 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
|
26
40
|
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
27
41
|
DEALINGS IN THE SOFTWARE.
|
|
28
42
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.raw = void 0;
|
|
40
|
-
const load_sources_1 = require("../../utils/load-sources");
|
|
41
|
-
function getSWCOptions({ filename, isNode, development, dynamicImport, disableShuviDynamic, hasReactRefresh }) {
|
|
42
|
-
const isTSFile = filename.endsWith('.ts');
|
|
43
|
-
const isTypeScript = isTSFile || filename.endsWith('.tsx');
|
|
44
|
-
const jsc = {
|
|
45
|
-
parser: {
|
|
46
|
-
syntax: isTypeScript ? 'typescript' : 'ecmascript',
|
|
47
|
-
dynamicImport,
|
|
48
|
-
// Exclude regular TypeScript files from React transformation to prevent e.g. generic parameters and angle-bracket type assertion from being interpreted as JSX tags.
|
|
49
|
-
[isTypeScript ? 'tsx' : 'jsx']: isTSFile ? false : true
|
|
50
|
-
},
|
|
51
|
-
transform: {
|
|
52
|
-
react: {
|
|
53
|
-
importSource: 'react',
|
|
54
|
-
runtime: 'automatic',
|
|
55
|
-
// runtime: 'classic',
|
|
56
|
-
pragma: 'React.createElement',
|
|
57
|
-
pragmaFrag: 'React.Fragment',
|
|
58
|
-
throwIfNamespace: true,
|
|
59
|
-
development,
|
|
60
|
-
useBuiltins: true,
|
|
61
|
-
refresh: hasReactRefresh
|
|
62
|
-
},
|
|
63
|
-
optimizer: {
|
|
64
|
-
simplify: false,
|
|
65
|
-
globals: {
|
|
66
|
-
typeofs: {
|
|
67
|
-
window: isNode ? 'undefined' : 'object'
|
|
68
|
-
},
|
|
69
|
-
envs: {
|
|
70
|
-
NODE_ENV: development ? '"development"' : '"production"'
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
regenerator: {
|
|
75
|
-
importPath: require.resolve('regenerator-runtime')
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
const isPageFile = true;
|
|
80
|
-
if (isNode) {
|
|
81
|
-
return {
|
|
82
|
-
jsc,
|
|
83
|
-
disableShuviDynamic,
|
|
84
|
-
isDevelopment: development,
|
|
85
|
-
isPageFile,
|
|
86
|
-
env: {
|
|
87
|
-
targets: {
|
|
88
|
-
// Targets the current version of Node.js
|
|
89
|
-
node: process.versions.node
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
// Matches default @babel/preset-env behavior
|
|
96
|
-
jsc.target = 'es5';
|
|
97
|
-
return {
|
|
98
|
-
disableShuviDynamic,
|
|
99
|
-
isDevelopment: development,
|
|
100
|
-
isPageFile,
|
|
101
|
-
jsc
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
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}`));
|
|
105
49
|
function loaderTransform(source, inputSourceMap) {
|
|
106
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
51
|
// Make the loader async
|
|
108
52
|
const filename = this.resourcePath;
|
|
109
|
-
let loaderOptions =
|
|
110
|
-
const {
|
|
111
|
-
const
|
|
112
|
-
|
|
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)({
|
|
113
70
|
filename,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
hasReactRefresh: hasReactRefresh !== undefined
|
|
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
|
|
119
83
|
});
|
|
120
84
|
const programmaticOptions = Object.assign(Object.assign({}, swcOptions), { filename, inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,
|
|
121
85
|
// Set the default sourcemap behavior based on Webpack's mapping flag,
|
|
@@ -136,7 +100,7 @@ function loaderTransform(source, inputSourceMap) {
|
|
|
136
100
|
programmaticOptions.jsc.transform.react.development =
|
|
137
101
|
this.mode === 'development';
|
|
138
102
|
}
|
|
139
|
-
return (0,
|
|
103
|
+
return (0, compiler_1.transform)(source, programmaticOptions).then(output => {
|
|
140
104
|
return [output.code, output.map ? JSON.parse(output.map) : undefined];
|
|
141
105
|
});
|
|
142
106
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const webpack_1 = require("webpack");
|
|
4
4
|
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
5
|
+
const IDENTITY_RUNTIME_PUBLICPATH = `__${constants_1.NAME}_dynamic_public_path__`;
|
|
5
6
|
const GLOBALTHIS = 'globalThis';
|
|
6
7
|
/**
|
|
7
8
|
* blog: use webpack build for production, just define __webpack_public_path__ to change asset url to quick release, without build again
|
|
@@ -42,8 +43,8 @@ class DynamicPublicPath extends webpack_1.RuntimeModule {
|
|
|
42
43
|
generate() {
|
|
43
44
|
return `
|
|
44
45
|
// server runtime public path
|
|
45
|
-
if (${GLOBALTHIS}["${
|
|
46
|
-
${webpack_1.RuntimeGlobals.publicPath} = ${GLOBALTHIS}["${
|
|
46
|
+
if (${GLOBALTHIS}["${IDENTITY_RUNTIME_PUBLICPATH}"]) {
|
|
47
|
+
${webpack_1.RuntimeGlobals.publicPath} = ${GLOBALTHIS}["${IDENTITY_RUNTIME_PUBLICPATH}"];
|
|
47
48
|
}
|
|
48
49
|
`;
|
|
49
50
|
}
|
|
@@ -23,6 +23,7 @@ declare const ModuleAction: {
|
|
|
23
23
|
export default class ModuleReplacePlugin implements Plugin {
|
|
24
24
|
private _options;
|
|
25
25
|
static restoreModule(id: string): false | Promise<any>;
|
|
26
|
+
static replaceModule(id: string): false | void;
|
|
26
27
|
constructor(options: Partial<ModuleReplacePluginOptions>);
|
|
27
28
|
apply(compiler: Compiler): void;
|
|
28
29
|
private _handleBuildModule;
|
|
@@ -75,12 +75,20 @@ class ModuleReplacePlugin {
|
|
|
75
75
|
moduleInfos.forEach(moduleInfo => {
|
|
76
76
|
moduleInfo.action = ModuleAction.RESTORE;
|
|
77
77
|
handler.pending.set(moduleInfo.compiler, false);
|
|
78
|
-
moduleInfo.compiler.hooks.invalid.call('noop', new Date().getTime());
|
|
79
78
|
});
|
|
80
79
|
return new Promise(resolve => {
|
|
81
80
|
handler.resolve = resolve;
|
|
82
81
|
});
|
|
83
82
|
}
|
|
83
|
+
static replaceModule(id) {
|
|
84
|
+
const moduleInfos = getKnownModules(id);
|
|
85
|
+
if (moduleInfos.length < 1) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
moduleInfos.forEach(moduleInfo => {
|
|
89
|
+
moduleInfo.action = ModuleAction.REPLACE;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
84
92
|
apply(compiler) {
|
|
85
93
|
var _a;
|
|
86
94
|
const { modules } = this._options;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/toolpack",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.11",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -9,13 +9,18 @@
|
|
|
9
9
|
"author": "liximomo",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"files": [
|
|
12
|
-
"lib"
|
|
13
|
-
"swc-source"
|
|
12
|
+
"lib"
|
|
14
13
|
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"dev": "tsc -p tsconfig.build.json -w",
|
|
16
|
+
"prebuild": "rimraf lib",
|
|
17
|
+
"build": "tsc -p tsconfig.build.json"
|
|
18
|
+
},
|
|
15
19
|
"engines": {
|
|
16
20
|
"node": ">= 12.0.0"
|
|
17
21
|
},
|
|
18
22
|
"dependencies": {
|
|
23
|
+
"@shuvi/compiler": "1.0.0-rc.11",
|
|
19
24
|
"@babel/core": "7.12.10",
|
|
20
25
|
"@babel/plugin-proposal-class-properties": "7.12.1",
|
|
21
26
|
"@babel/plugin-proposal-nullish-coalescing-operator": "7.10.1",
|
|
@@ -29,11 +34,9 @@
|
|
|
29
34
|
"@babel/preset-react": "7.10.1",
|
|
30
35
|
"@babel/preset-typescript": "7.12.7",
|
|
31
36
|
"@babel/runtime": "7.12.5",
|
|
32
|
-
"@napi-rs/cli": "1.2.1",
|
|
33
|
-
"@napi-rs/triples": "1.0.3",
|
|
34
37
|
"@parcel/css": "1.2.0",
|
|
35
|
-
"@shuvi/shared": "1.0.0-rc.
|
|
36
|
-
"@shuvi/utils": "1.0.0-rc.
|
|
38
|
+
"@shuvi/shared": "1.0.0-rc.11",
|
|
39
|
+
"@shuvi/utils": "1.0.0-rc.11",
|
|
37
40
|
"babel-loader": "8.2.2",
|
|
38
41
|
"babel-plugin-syntax-jsx": "6.18.0",
|
|
39
42
|
"babel-plugin-transform-define": "2.0.0",
|
|
@@ -49,43 +52,30 @@
|
|
|
49
52
|
"esbuild-loader": "^2.19.0",
|
|
50
53
|
"file-loader": "6.2.0",
|
|
51
54
|
"fork-ts-checker-webpack-plugin": "6.0.8",
|
|
55
|
+
"fs-extra": "9.0.1",
|
|
52
56
|
"ignore-loader": "0.1.2",
|
|
53
57
|
"loader-utils": "2.0.0",
|
|
54
58
|
"mini-css-extract-plugin": "1.3.9",
|
|
55
59
|
"mrmime": "1.0.0",
|
|
56
60
|
"path-browserify": "1.0.1",
|
|
57
|
-
"postcss": "8.
|
|
61
|
+
"postcss": "8.4.14",
|
|
58
62
|
"postcss-flexbugs-fixes": "5.0.2",
|
|
59
63
|
"postcss-loader": "4.1.0",
|
|
60
64
|
"postcss-preset-env": "6.7.0",
|
|
61
65
|
"process": "0.11.10",
|
|
62
|
-
"react-error-overlay": "6.0.8",
|
|
63
66
|
"regenerator-runtime": "^0.13.9",
|
|
67
|
+
"@swc/helpers": "0.4.3",
|
|
64
68
|
"sass-loader": "10.1.0",
|
|
65
69
|
"stream-browserify": "3.0.0",
|
|
66
|
-
"strip-ansi": "6.0.0",
|
|
67
70
|
"style-loader": "2.0.0",
|
|
68
71
|
"terser-webpack-plugin": "5.2.5",
|
|
72
|
+
"typescript": "4.7.4",
|
|
69
73
|
"vm-browserify": "1.1.2",
|
|
70
74
|
"webpack": "5.73.0",
|
|
71
75
|
"webpack-bundle-analyzer": "4.3.0",
|
|
72
76
|
"webpack-chain": "6.5.1",
|
|
73
|
-
"webpack-dev-middleware": "4.1.0",
|
|
74
77
|
"webpack-sources": "2.2.0",
|
|
75
|
-
"webpack-virtual-modules": "0.4.3"
|
|
76
|
-
"fs-extra": "9.0.1"
|
|
77
|
-
},
|
|
78
|
-
"optionalDependencies": {
|
|
79
|
-
"@shuvi/swc-darwin-arm64": "latest",
|
|
80
|
-
"@shuvi/swc-darwin-x64": "latest",
|
|
81
|
-
"@shuvi/swc-linux-arm-gnueabihf": "latest",
|
|
82
|
-
"@shuvi/swc-linux-arm64-gnu": "latest",
|
|
83
|
-
"@shuvi/swc-linux-arm64-musl": "latest",
|
|
84
|
-
"@shuvi/swc-linux-x64-gnu": "latest",
|
|
85
|
-
"@shuvi/swc-linux-x64-musl": "latest",
|
|
86
|
-
"@shuvi/swc-win32-arm64-msvc": "latest",
|
|
87
|
-
"@shuvi/swc-win32-ia32-msvc": "latest",
|
|
88
|
-
"@shuvi/swc-win32-x64-msvc": "latest"
|
|
78
|
+
"webpack-virtual-modules": "0.4.3"
|
|
89
79
|
},
|
|
90
80
|
"devDependencies": {
|
|
91
81
|
"@types/babel__core": "^7.1.19",
|
|
@@ -93,30 +83,6 @@
|
|
|
93
83
|
"@types/loader-utils": "2.0.1",
|
|
94
84
|
"@types/mini-css-extract-plugin": "^1.2.2",
|
|
95
85
|
"@types/webpack-bundle-analyzer": "^3.8.0",
|
|
96
|
-
"@types/webpack-dev-middleware": "5.0.2",
|
|
97
86
|
"memfs": "^3.1.2"
|
|
98
|
-
},
|
|
99
|
-
"napi": {
|
|
100
|
-
"name": "shuvi-swc",
|
|
101
|
-
"triples": {
|
|
102
|
-
"defaults": true,
|
|
103
|
-
"additional": [
|
|
104
|
-
"i686-pc-windows-msvc",
|
|
105
|
-
"aarch64-unknown-linux-gnu",
|
|
106
|
-
"armv7-unknown-linux-gnueabihf",
|
|
107
|
-
"aarch64-apple-darwin",
|
|
108
|
-
"x86_64-unknown-freebsd",
|
|
109
|
-
"x86_64-unknown-linux-musl",
|
|
110
|
-
"aarch64-unknown-linux-musl",
|
|
111
|
-
"aarch64-pc-windows-msvc"
|
|
112
|
-
]
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
"scripts": {
|
|
116
|
-
"dev": "tsc -p tsconfig.build.json -w",
|
|
117
|
-
"prebuild": "rimraf lib",
|
|
118
|
-
"build": "tsc -p tsconfig.build.json",
|
|
119
|
-
"build-native": "napi build --platform --cargo-cwd /src/swc ./swc-source/native",
|
|
120
|
-
"publish-native": "node scripts/publish-native.js"
|
|
121
87
|
}
|
|
122
|
-
}
|
|
88
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|