
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
@nutui/babel-plugin-separate-import
Advanced tools
按需引入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"
}]
]
}
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
选项,则不会加载样式文件,需用户手动添加;
FAQs
按需构建nutui2.0的组件,减小打包体积
The npm package @nutui/babel-plugin-separate-import receives a total of 10 weekly downloads. As such, @nutui/babel-plugin-separate-import popularity was classified as not popular.
We found that @nutui/babel-plugin-separate-import demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.