@modern-js/plugin-swc 2.26.0 → 2.28.0
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/CHANGELOG.md +24 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +98 -53
- package/package.json +12 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 2.28.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [b7b4d84]
|
|
8
|
+
- Updated dependencies [ac0e99c]
|
|
9
|
+
- Updated dependencies [00b58a7]
|
|
10
|
+
- @modern-js/builder-plugin-swc@2.28.0
|
|
11
|
+
- @modern-js/utils@2.28.0
|
|
12
|
+
|
|
13
|
+
## 2.27.0
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 8322a51: chore: migrate packages from tsc to module-lib build
|
|
18
|
+
|
|
19
|
+
chore: 将使用 tsc 的包迁移到 module-lib 构建
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [91d14b8]
|
|
22
|
+
- Updated dependencies [8322a51]
|
|
23
|
+
- Updated dependencies [6d7104d]
|
|
24
|
+
- @modern-js/utils@2.27.0
|
|
25
|
+
- @modern-js/builder-plugin-swc@2.27.0
|
|
26
|
+
|
|
3
27
|
## 2.26.0
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { AppTools, CliPlugin } from '@modern-js/app-tools';
|
|
2
2
|
import { PluginSwcOptions } from '@modern-js/builder-plugin-swc';
|
|
3
|
+
import type { ToolsUserConfig } from '@modern-js/app-tools/src/types/config/tools';
|
|
3
4
|
export declare function factory(name: string, modifySwcOptions: (options: PluginSwcOptions) => PluginSwcOptions): () => CliPlugin<AppTools>;
|
|
5
|
+
export declare function applyBuilderSwcConfig(swc: PluginSwcOptions, esbuild: ToolsUserConfig['esbuild'] | undefined, isSSR: boolean): PluginSwcOptions;
|
|
4
6
|
export declare const swcPlugin: () => CliPlugin<AppTools>;
|
|
5
|
-
export default swcPlugin;
|
|
7
|
+
export default swcPlugin;
|
package/dist/index.js
CHANGED
|
@@ -1,59 +1,104 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
factory: function() {
|
|
14
|
+
return factory;
|
|
15
|
+
},
|
|
16
|
+
applyBuilderSwcConfig: function() {
|
|
17
|
+
return applyBuilderSwcConfig;
|
|
18
|
+
},
|
|
19
|
+
swcPlugin: function() {
|
|
20
|
+
return swcPlugin;
|
|
21
|
+
},
|
|
22
|
+
default: function() {
|
|
23
|
+
return _default;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const _utils = require("@modern-js/utils");
|
|
27
|
+
const _builderpluginswc = require("@modern-js/builder-plugin-swc");
|
|
28
|
+
const _logger = require("@modern-js/utils/logger");
|
|
7
29
|
function factory(name, modifySwcOptions) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
return () => ({
|
|
31
|
+
name,
|
|
32
|
+
setup: (api) => ({
|
|
33
|
+
validateSchema() {
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
target: "tools.swc",
|
|
37
|
+
schema: {
|
|
38
|
+
typeof: [
|
|
39
|
+
"object"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
},
|
|
45
|
+
prepare() {
|
|
46
|
+
const context = api.useAppContext();
|
|
47
|
+
if (!context.builder || context.bundlerType === "rspack") {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const config = api.useResolvedConfigContext();
|
|
51
|
+
const { esbuild, swc = {} } = config.tools;
|
|
52
|
+
const swcOptions = modifySwcOptions(swc);
|
|
53
|
+
const finalConfig = applyBuilderSwcConfig(swcOptions, esbuild, (0, _utils.isSSR)(config));
|
|
54
|
+
context.builder.addPlugins([
|
|
55
|
+
(0, _builderpluginswc.builderPluginSwc)(finalConfig)
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function applyBuilderSwcConfig(swc, esbuild, isSSR) {
|
|
62
|
+
if (isSSR) {
|
|
63
|
+
swc = applyConfig(swc, (config) => {
|
|
64
|
+
config.extensions = {
|
|
65
|
+
...config.extensions || {},
|
|
66
|
+
loadableComponents: true
|
|
67
|
+
};
|
|
45
68
|
});
|
|
69
|
+
}
|
|
70
|
+
return applyConfig(swc, (config) => {
|
|
71
|
+
if (esbuild) {
|
|
72
|
+
if (config.jsMinify !== false && esbuild.minimize !== false) {
|
|
73
|
+
_logger.logger.warn("You have enabled both esbuild minimizer and SWC minimizer, which will cause conflicts. Please remove `tools.esbuild` config and only use SWC to minimize your code.");
|
|
74
|
+
}
|
|
75
|
+
if (esbuild.loader !== false) {
|
|
76
|
+
_logger.logger.warn("You have enabled both esbuild loader and SWC loader, which will cause conflicts. Please remove `tools.esbuild` config and only use SWC to transform your code.");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
46
80
|
}
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
81
|
+
const PLUGIN_NAME = "@modern-js/plugin-swc";
|
|
82
|
+
const swcPlugin = factory(PLUGIN_NAME, (swcOptions) => {
|
|
83
|
+
return applyConfig(swcOptions, (swcOptions2) => {
|
|
84
|
+
swcOptions2.extensions = {
|
|
85
|
+
...swcOptions2.extensions || {},
|
|
86
|
+
ssrLoaderId: {
|
|
87
|
+
runtimePackageName: "@modern-js/runtime",
|
|
88
|
+
functionUseLoaderName: "useLoader"
|
|
89
|
+
}
|
|
56
90
|
};
|
|
57
|
-
|
|
91
|
+
});
|
|
58
92
|
});
|
|
59
|
-
|
|
93
|
+
function applyConfig(rawConfig, handler) {
|
|
94
|
+
if (typeof rawConfig === "function") {
|
|
95
|
+
return (config, utils) => {
|
|
96
|
+
handler(config);
|
|
97
|
+
return rawConfig(config, utils);
|
|
98
|
+
};
|
|
99
|
+
} else {
|
|
100
|
+
handler(rawConfig);
|
|
101
|
+
return rawConfig;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const _default = swcPlugin;
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"modern",
|
|
15
15
|
"modern.js"
|
|
16
16
|
],
|
|
17
|
-
"version": "2.
|
|
17
|
+
"version": "2.28.0",
|
|
18
18
|
"jsnext:source": "./src/index.ts",
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
20
20
|
"main": "./dist/index.js",
|
|
@@ -30,18 +30,19 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@modern-js/
|
|
33
|
+
"@swc/helpers": "0.5.1",
|
|
34
|
+
"@modern-js/builder-plugin-swc": "2.28.0",
|
|
35
|
+
"@modern-js/utils": "2.28.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@types/jest": "^29",
|
|
38
38
|
"@types/node": "^14",
|
|
39
|
+
"@types/jest": "^29",
|
|
39
40
|
"typescript": "^5",
|
|
40
|
-
"@modern-js/
|
|
41
|
-
"@modern-js/
|
|
42
|
-
"@
|
|
43
|
-
"@scripts/
|
|
44
|
-
"@
|
|
41
|
+
"@modern-js/types": "2.28.0",
|
|
42
|
+
"@modern-js/app-tools": "2.28.0",
|
|
43
|
+
"@scripts/jest-config": "2.28.0",
|
|
44
|
+
"@scripts/build": "2.28.0",
|
|
45
|
+
"@modern-js/builder-shared": "2.28.0"
|
|
45
46
|
},
|
|
46
47
|
"publishConfig": {
|
|
47
48
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -50,8 +51,8 @@
|
|
|
50
51
|
},
|
|
51
52
|
"scripts": {
|
|
52
53
|
"new": "modern-lib new",
|
|
53
|
-
"build": "
|
|
54
|
-
"dev": "
|
|
54
|
+
"build": "modern-lib build",
|
|
55
|
+
"dev": "modern-lib build --watch",
|
|
55
56
|
"test": "jest"
|
|
56
57
|
}
|
|
57
58
|
}
|