@nutui/babel-plugin-separate-import
Advanced tools
Comparing version 0.1.6 to 0.1.7
19
index.js
@@ -16,3 +16,4 @@ const {join} = require('path'); | ||
return specifiers.reduce(function(newSpecifiers, curr) { | ||
const isLocale = isLocaleExtra(curr); | ||
const _curr = curr.toLowerCase(); | ||
const isLocale = isLocaleExtra(_curr); | ||
const {style, sourceCode} = opts; | ||
@@ -25,6 +26,6 @@ const importLocal = t.identifier(curr); | ||
isLocale? imported: importDefault | ||
], t.stringLiteral(getTarget(curr, packagesPath, sourceCode))) | ||
], t.stringLiteral(getTarget(_curr, packagesPath, sourceCode))) | ||
] | ||
if(style && !isLocale) { | ||
const cssTarget = `${packagesPath + curr}/${curr}`; | ||
const cssTarget = `${packagesPath + _curr}/${_curr}`; | ||
imports.push(t.importDeclaration([], t.stringLiteral(`${cssTarget}.${style}`))) | ||
@@ -42,5 +43,5 @@ } | ||
if(isSourceCode) { | ||
const isLocale = isLocaleExtra(curr); | ||
const isExportFunc = isExportFuncExtra(curr); | ||
const localePath = join(pkgPath, '..', 'locale'); | ||
const isLocale = isLocaleExtra(pkgName); | ||
const isExportFunc = isExportFuncExtra(pkgName); | ||
const localePath = join(pkgPath, '..', 'locales'); | ||
const exportFuncTarget = `${pkgPath}/${pkgName}/_${pkgName}.js`; | ||
@@ -52,3 +53,2 @@ const sourceFile = `${pkgPath + pkgName}/${pkgName}.vue`; | ||
} | ||
console.log('\n\n\n\n\n\nisSourceCode,', isSourceCode, target); | ||
return target; | ||
@@ -62,7 +62,6 @@ } | ||
ImportDeclaration(path, {opts = {}}) { | ||
if(!opts.libraryName) opts.libraryName = '@nutui/nutui2'; | ||
if(!opts.libraryName) opts.libraryName = '@nutui/nutui'; | ||
if(!opts.sourceCode) opts.sourceCode = false; | ||
const {style} = opts; | ||
if(style) opts.style = style === 'scss'? 'scss': 'css'; | ||
const {node} = path; | ||
@@ -73,3 +72,3 @@ if(!node.source) return; | ||
if(value === opts.libraryName && specifiers && specifiers.length) { | ||
const spes = specifiers.filter(specifier => specifier.type === 'ImportSpecifier').map(specifier => specifier.local.name.toLowerCase()); | ||
const spes = specifiers.filter(specifier => specifier.type === 'ImportSpecifier').map(specifier => specifier.local.name); | ||
if(spes.length) { | ||
@@ -76,0 +75,0 @@ path.replaceWithMultiple(genImportDeclaration(spes, opts)) |
{ | ||
"name": "@nutui/babel-plugin-separate-import", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "按需构建nutui2.0的组件,减小打包体积", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
6427