Gathering detailed insights and metrics for swc-plugin-another-transform-imports
Gathering detailed insights and metrics for swc-plugin-another-transform-imports
Gathering detailed insights and metrics for swc-plugin-another-transform-imports
Gathering detailed insights and metrics for swc-plugin-another-transform-imports
Another wasm swc transform imports plugin
npm install swc-plugin-another-transform-imports
Typescript
Module System
Node Version
NPM Version
67.3
Supply Chain
92.7
Quality
79.8
Maintenance
100
Vulnerability
100
License
Rust (87.21%)
TypeScript (12.36%)
Just (0.43%)
Total Downloads
407,307
Last Day
177
Last Week
2,890
Last Month
21,422
Last Year
155,361
13 Stars
28 Commits
3 Forks
2 Watching
3 Branches
1 Contributors
Latest Version
1.7.0
Package Id
swc-plugin-another-transform-imports@1.7.0
Unpacked Size
754.65 kB
Size
265.41 kB
File Count
5
NPM Version
10.8.2
Node Version
22.7.0
Publised On
12 Sept 2024
Cumulative downloads
Total Downloads
Last day
-80.6%
177
Compared to previous day
Last week
-50.9%
2,890
Compared to previous week
Last month
-6.7%
21,422
Compared to previous month
Last year
-38.2%
155,361
Compared to previous year
4
Another wasm plugin for swc, inspired from babel-plugin-transform-imports.
1npm install --save-dev swc-plugin-another-transform-imports 2# or 3yarn add -D swc-plugin-another-transform-imports
It follows resolving rule of node.js, can be use in .swcrc
,webpack.config.js
or next.config.js
and so on. For Example:
1{ 2 "jsc": { 3 "experimental": { 4 "plugins": [ 5 [ 6 "swc-plugin-another-transform-imports", 7 { 8 "antd": { 9 "transform": "antd/lib/${member}", 10 "skipDefaultConversion": false, 11 "preventFullImport": true, 12 "style": "antd/lib/${member}/style", 13 "memberTransformers": ["dashed_case"] 14 }, 15 "lodash": { 16 "transform": "lodash/${member}", 17 "preventFullImport": true 18 } 19 } 20 ] 21 ] 22 } 23 } 24}
Can convert the following lines:
1import { Button as MyButton, BackTop } from "antd"; 2import { merge } from "lodash";
To:
1import MyButton from "antd/lib/button"; 2import BackTop from "antd/lib/back-top"; 3import "antd/lib/back-top/style"; 4import "antd/lib/button/style"; 5import merge from "lodash/merge";
Ensure you read next.js compiler docs first!!!!
Since the semantic version association of @swc/core
(npm) and swc_core
(rust) for next.js is still experimental. next.js has a lot of breaking change in the swc native plugin mechanism between major and even minor versions.
It is possible that as next.js and swc are updated, the current plugin will fail in the new version. Hopefully the new plugin api for swc will be stable soon. Here is the current version correspondence.
next.js versions | swc_versions | This package version |
---|---|---|
12.3.x | - | 0.1.5 |
13.0.x | - | 0.2.1 |
13.2.4 ~ 13.3.1 | - | not support https://github.com/vercel/next.js/issues/46989#issuecomment-1486989081 |
13.3.1 ~ 13.4.3 | - | 0.2.3 |
13.4.3-canary.2 ~ 13.4.7 | 1.3.58 ~ 1.3.62 | 0.2.4 |
13.4.8 ~ v13.4.10-canary.0 | 1.3.63 ~ 1.3.67 | 0.2.5 |
13.4.10-canary.1 ~ | 1.3.68 ~ 1.3.80 | 0.2.6 |
~ 14.1.0 | 1.3.81 ~ 1.3.105 | 0.2.7 |
- | 1.3.106 ~ 1.3.107 | 0.2.8 |
14.1.1-canary.52 ~ 15.0.0-canary.28 | 1.4.x | 0.2.9 |
15.0.0-canary.29 ~ 15.0.0-canary.36 | 1.5.x | 1.5.0 |
15.0.0-canary.37 ~ 15.0.0-canary.116 | 1.6.x | 1.6.0 |
15.0.0-canary.117 ~ | 1.7.x | 1.7.0 |
@swc/core and swc_core version mappings
antd/es/xxx/style
and antd/lib/xxx/style
will introduce less
, please add less-loader
by yourself.
If you use antd and next.js at the same time, it will be a bit troublesome to work with them, you can use next-plugin-antd-less
for convenience, see issue 1 for an example.
Name | Type | Required | Default | Description |
---|---|---|---|---|
transform | string | yes | undefined | The library name to use instead of the one specified in the import statement. ${member} will be replaced with the member, aka Grid/Row/Col/etc. |
preventFullImport | boolean | no | true | Whether or not to throw when an import is encountered which would cause the entire module to be imported. |
skipDefaultConversion | boolean | no | false | When set to true, will preserve import { X } syntax instead of converting to import X . |
style | string | no | false | The style path of the member, ${member} will be replaced with the member, aka Grid/Row/Col/etc. |
memberTransformers | Array<MemberTransformer> | no | [] | Member transformers |
type MemberTransformer
1type MemberTransformer = 2 | "camel_case" 3 | "kebab_case" 4 | "pascal_case" 5 | "snake_case" 6 | "upper_case" 7 | "upper_first" 8 | "lower_case" 9 | "lower_first" 10 | "dashed_case";
Usually upgrading to the latest version of @swc/core and other swc tools will solve the problem, see the following issue for typical solution:
You can simply fork this plugin, modify its source code to suit your custom needs. For fast validation, you don't necessarily have to publish the modified project, but simply require your wasm file to the project. For example:
1cargo prepublish
or
1npm run prepublish
Then copy your wasm target file, and set your config to:
1module.exports = { 2 ..., 3 "jsc": { 4 "experimental": { 5 "plugins": [ 6 [ 7 require.resolve("./path/to/your-modified-plugin.wasm"), 8 { 9 ..your options 10 } 11 ] 12 ] 13 } 14 }, 15 ... 16}
No vulnerabilities found.
No security vulnerabilities found.