Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nutui/babel-plugin-separate-import

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nutui/babel-plugin-separate-import

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

  • 1.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
Maintainers
1
Weekly downloads
 
Created
Source

@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选项,则不会加载样式文件,需用户手动添加;

Keywords

FAQs

Package last updated on 22 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc