npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nutui/babel-plugin-separate-import

v1.2.2

Published

按需构建nutui2.0的组件,减小打包体积

Downloads

52

Readme

@nutui/babel-plugin-separate-import


按需引入Nutui2.0组件,减小打包体积;

安装


npm i -D @nutui/babel-plugin-separate-import

使用


配置.babelrc文件:

{
  "plugins": [
    ["@nutui/babel-plugin-separate-import", {
      "style": "css"
    }]
  ]
}

然后就可以像下面这样按需引入组件了:

import Vue from 'vue';
import { Button, Icon } from '@nutui/nutui';

Vue.use(Button);
Vue.use(Icon);

国际化

如果您需要使用我们的国际化功能,并使用我们的语言转换方法来对自己的网站进行语言转换的话,需要配置该插件的 sourceCode 参数为 true;此时组件的按需引用和默认情况下不同,组件将会指向未构建的源文件,同时组件也不再具有 install 方法,请使用 Vue.component 对组件进行注册;

import Vue from 'vue';
import { Button, Icon, locale, i18n } from '@nutui/nutui';

Vue.component(Button.name, Button);
Vue.component(Icon.name, Icon);
// .babelrc

{
  "plugins": [
    ["@nutui/babel-plugin-separate-import", {
      "sourceCode": true,
      "style": "css"
    }]
  ]
}

AST转换


import { Button } from '@nutui/nutui';

当使用这种方式import组件时,将会被转换为:

import Button from '@nutui/nutui/dist/packages/button/button.js';
// sourceCode 为 true 时
import Button from '@nutui/nutui/dist/packages/button/button.vue';

import '@nutui/nutui/dist/packages/button/button.css';
  • 如果style选项为css,则会加载相应组件的css

  • 如果style选项为scss,则会加载相应组件的scss

  • 如果没有style选项,则不会加载样式文件,需用户手动添加;