Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ tmp
node_modules
coverage
lib
.DS_Store
.DS_Store
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = function core(defaultLibraryName) {
styleLibrary,
root = '',
camel2Dash = true,
exclusions = [],
} = options;
let styleLibraryName = options.styleLibraryName;
let _root = root;
Expand All @@ -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}`;
}
Expand All @@ -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(/^~/, '');
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/exclusions/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

import Vue from 'vue'

import { TabbarItem, Lazyload } from 'vant'

Vue.use(Lazyload)
Vue.use(TabbarItem)
13 changes: 13 additions & 0 deletions test/fixtures/exclusions/expected.js
Original file line number Diff line number Diff line change
@@ -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);
9 changes: 9 additions & 0 deletions test/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down