swc-plugin-import-on-demand
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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

  1. '[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';
  2. 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";

Readme

Keywords

none

Package Sidebar

Install

npm i swc-plugin-import-on-demand

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

7.84 kB

Total Files

4

Last publish

Collaborators

  • monako