diff --git a/.gitignore b/.gitignore index 5d5f091a..3acd20e2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ tmp node_modules coverage lib -.DS_Store +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index aa1f7073..efa76aed 100644 --- a/README.md +++ b/README.md @@ -137,3 +137,4 @@ or - `["component", { "libDir": "lib" }]`: lib directory - `["component", { "root": "index" }]`: main file dir - `["component", { "camel2Dash": false }]`: whether parse name to dash mode or not, default `true` +- `["component", { exclusions: ["Lazyload"]}]` exclude component that without css file \ No newline at end of file diff --git a/src/core.js b/src/core.js index 584f7c07..fac1d0ae 100644 --- a/src/core.js +++ b/src/core.js @@ -40,6 +40,7 @@ module.exports = function core(defaultLibraryName) { styleLibrary, root = '', camel2Dash = true, + exclusions = [], } = options; let styleLibraryName = options.styleLibraryName; let _root = root; @@ -48,7 +49,8 @@ module.exports = function core(defaultLibraryName) { let styleRoot; let mixin = false; const ext = options.ext || '.css'; - + const index = exclusions.findIndex((exclusion) => exclusion === methodName); + const shouldImportCss = !(index > -1); if (root) { _root = `/${root}`; } @@ -71,6 +73,7 @@ module.exports = function core(defaultLibraryName) { mixin = styleLibrary.mixin; styleRoot = styleLibrary.root; } + if (!shouldImportCss) return selectedMethods[methodName]; if (styleLibraryName) { if (!cachePath[libraryName]) { const themeName = styleLibraryName.replace(/^~/, ''); diff --git a/test/fixtures/exclusions/actual.js b/test/fixtures/exclusions/actual.js new file mode 100644 index 00000000..df316d19 --- /dev/null +++ b/test/fixtures/exclusions/actual.js @@ -0,0 +1,7 @@ + +import Vue from 'vue' + +import { TabbarItem, Lazyload } from 'vant' + +Vue.use(Lazyload) +Vue.use(TabbarItem) diff --git a/test/fixtures/exclusions/expected.js b/test/fixtures/exclusions/expected.js new file mode 100644 index 00000000..a8c238e5 --- /dev/null +++ b/test/fixtures/exclusions/expected.js @@ -0,0 +1,13 @@ +"use strict"; + +var _tabbarItem = _interopRequireDefault(require("vant/lib/tabbar-item")); + +var _lazyload = _interopRequireDefault(require("vant/lib/lazyload")); + +var _vue = _interopRequireDefault(require("vue")); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +_vue.default.use(_lazyload.default); + +_vue.default.use(_tabbarItem.default); \ No newline at end of file diff --git a/test/index-test.js b/test/index-test.js index 0ed00348..5f93e5c2 100644 --- a/test/index-test.js +++ b/test/index-test.js @@ -133,6 +133,15 @@ describe('index', () => { }]; } + if (caseName === 'exclusions') { + cssPlugin = [plugin, { + libraryName: 'vant', + styleLibraryName: 'vant-css', + exclusions: ['Lazyload', 'TabbarItem'], + style: true, + }]; + } + const actual = transformFileSync(actualFile, { presets: ['@babel/react'], plugins: cssPlugin && Array.isArray(cssPlugin[1]) ? cssPlugin : [cssPlugin || plugin],