vite-plugin-importer-next
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

vite-plugin-importer-next

fork from vite-plugin-importer, the only diffrent is that this module support parsing babel configuration automatically.

NPM version NPM Downloads

features

  • Lookup babel config automatically
  • Integration for babel-plugin-import/babel-plugin-component

use

config same as babel-plugin-import & babel-plugin-component

npm install vite-plugin-importer-next --save
yarn add vite-plugin-importer-next
// vite.config.js
import { defineConfig } from "vite";
import usePluginImport from 'vite-plugin-importer-next'
export default defineConfig({
  plugins: [
    ... // other plugins
    // if not pass param, it will lookup babel config of project root
    // babel.config.js、babel.config.cjs、babel.config.mjs、babel.config.json
    // package.json、 .babelrc、.babelrc.js、.babelrc.cjs、.babelrc.mjs、.babelrc.json
    usePluginImport(),
    usePluginImport({
      libraryName: "ant-design-vue",
      libraryDirectory: "es",
      style: true,
    }),
    usePluginImport({
      libraryName: "antd",
      libraryDirectory: "es",
      style: true,
    }),
    usePluginImport({
      libraryName: 'vant',
      libraryDirectory: 'es',
      style: (name) => `${name}/style/less`,
    }),
    usePluginImport({
      libraryName: 'element-plus',
      customStyleName: (name) => {
        return `element-plus/lib/theme-chalk/${name}.css`;
      },
    })
    // Other configurations welcome PR
  ];
})

or in a .babelrc config

"plugins": [
  [
    "import",
    {
      "libraryName": "element-ui",
      "style": true
    }
  ]
]

LICENSE

MIT

Package Sidebar

Install

npm i vite-plugin-importer-next

Weekly Downloads

1

Version

0.2.2

License

MIT

Unpacked Size

12.6 kB

Total Files

7

Last publish

Collaborators

  • zt123123