{"id":18484160,"url":"https://github.com/jdf2e/separate-import","last_synced_at":"2025-04-08T18:33:09.293Z","repository":{"id":57132427,"uuid":"156513358","full_name":"jdf2e/separate-import","owner":"jdf2e","description":"按需引入Nutui2.0组件，减小打包体积","archived":false,"fork":false,"pushed_at":"2023-04-29T19:39:42.000Z","size":12,"stargazers_count":5,"open_issues_count":1,"forks_count":4,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-18T05:24:58.462Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/jdf2e/nutui-lib/tree/master/babel-plugin-separate-import","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jdf2e.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-07T08:22:16.000Z","updated_at":"2020-06-23T07:18:24.000Z","dependencies_parsed_at":"2024-11-06T12:45:43.621Z","dependency_job_id":"4557ed90-6bbb-4bfa-9384-1ea2957a5551","html_url":"https://github.com/jdf2e/separate-import","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdf2e%2Fseparate-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdf2e%2Fseparate-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdf2e%2Fseparate-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdf2e%2Fseparate-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdf2e","download_url":"https://codeload.github.com/jdf2e/separate-import/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247902746,"owners_count":21015508,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T12:38:47.015Z","updated_at":"2025-04-08T18:33:05.284Z","avatar_url":"https://github.com/jdf2e.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### @nutui/babel-plugin-separate-import\n\n---\n\n按需引入Nutui2.0组件，减小打包体积；\n\n### 安装\n\n---\n\n```bash\nnpm i -D @nutui/babel-plugin-separate-import\n```\n\n### 使用\n\n---\n\n配置`.babelrc`文件：\n\n```js\n{\n  \"plugins\": [\n    [\"@nutui/babel-plugin-separate-import\", {\n      \"style\": \"css\"\n    }]\n  ]\n}\n\n```\n\n然后就可以像下面这样按需引入组件了：\n\n```js\nimport Vue from 'vue';\nimport { Button, Icon } from '@nutui/nutui';\n\nVue.use(Button);\nVue.use(Icon);\n```\n\n### 国际化\n\n如果您需要使用我们的国际化功能，并使用我们的语言转换方法来对自己的网站进行语言转换的话，需要配置该插件的 `sourceCode` 参数为 `true`；此时组件的按需引用和默认情况下不同，组件将会指向未构建的源文件，同时组件也不再具有 `install` 方法，请使用 `Vue.component` 对组件进行注册；\n\n```js\nimport Vue from 'vue';\nimport { Button, Icon, locale, i18n } from '@nutui/nutui';\n\nVue.component(Button.name, Button);\nVue.component(Icon.name, Icon);\n```\n\n```js\n// .babelrc\n\n{\n  \"plugins\": [\n    [\"@nutui/babel-plugin-separate-import\", {\n      \"sourceCode\": true,\n      \"style\": \"css\"\n    }]\n  ]\n}\n```\n\n### AST转换\n\n---\n\n```js\nimport { Button } from '@nutui/nutui';\n```\n\n当使用这种方式`import`组件时，将会被转换为：\n\n```js\nimport Button from '@nutui/nutui/dist/packages/button/button.js';\n// sourceCode 为 true 时\nimport Button from '@nutui/nutui/dist/packages/button/button.vue';\n\nimport '@nutui/nutui/dist/packages/button/button.css';\n```\n\n* 如果`style`选项为`css`，则会加载相应组件的`css`；\n\n* 如果`style`选项为`scss`，则会加载相应组件的`scss`；\n\n* 如果没有`style`选项，则不会加载样式文件，需用户手动添加；\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdf2e%2Fseparate-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdf2e%2Fseparate-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdf2e%2Fseparate-import/lists"}