swc-plugin-import-on-demand
v1.0.2
Published
swc按需引入插件
Downloads
13
Readme
swc-plugin-import-on-demand
swc按需引入插件
install
npm i swc-plugin-import-on-demand -D
# or
yarn add swc-plugin-import-on-demand -D
Config
import ImportOnDemand from 'swc-plugin-import-on-demand';
// .swcrc
swcrc: {
plugin: (m: Program) =>
new ImportOnDemand({
lodash: '[source]/[name]',
}).visitProgram(m),
},
Example
'[source]/[name]'
swcrc
{ plugin: (m: Program) => new ImportOnDemand({ lodash: '[source]/[name]', }).visitProgram(m), }
preview
import { isFunction, isEqual } from 'lodash'; ↓ ↓ ↓ ↓ ↓ ↓ import isFunction from 'lodash/isFunction'; import isEqual from 'lodash/isEqual';
transform
swcrc
{ plugin: (m: Program) => new ImportOnDemand({ antd: ['[source]/es/[name:-]', '[source]/es/[name:-]/style'], '@ant-design/icons': { transform: ({ name, source }) => { if (name === 'createFromIconfontCN') { return `${source}/es/components/IconFont`; } return `${source}/es/icons/${name}`; }, }, }).visitProgram(m), }
preview
import { Button, DatePicker } from 'antd'; import { createFromIconfontCN, AccountBookFilled } from '@ant-design/icons'; import type { ColumnsType } from 'antd/es/table'; ↓ ↓ ↓ ↓ ↓ ↓ import Button from 'antd/es/button'; import from 'antd/es/button/style'; import DatePicker from 'antd/es/date-picker'; import from 'antd/es/date-picker/style'; import createFromIconfontCN from "@ant-design/icons/es/icons/components/IconFont.js"; import AccountBookFilled from "@ant-design/icons/es/icons/AccountBookFilled";