0.2.2 • Published 2 years ago

vite-plugin-importer-next v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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