Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nutui/babel-plugin-separate-import

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nutui/babel-plugin-separate-import - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

34

index.js

@@ -14,9 +14,6 @@ const {join} = require('path');

function genImportDeclaration(specifiers = [], opts) {
const packagesPath = `${opts.libraryName}/dist/packages/`;
const packagesPath = `@nutui/nutui/dist/packages/`;
return specifiers.reduce(function(newSpecifiers, curr) {
const isLocale = isLocaleExtra(curr);
const isExportFunc = isExportFuncExtra(curr);
const target = `${packagesPath + curr}/${curr}`;
const localePath = join(packagesPath, '..', 'locale');
const {style} = opts;
const {style, sourceCode} = opts;
const importLocal = t.identifier(curr);

@@ -28,6 +25,7 @@ const importDefault = t.importDefaultSpecifier(importLocal);

isLocale? imported: importDefault
], t.stringLiteral(isLocale? localePath: isExportFunc? `${packagesPath}/${curr}/_${curr}.js`: `${target.toLowerCase()}.vue`))
], t.stringLiteral(getTarget(curr, packagesPath, sourceCode)))
]
if(style && !isLocale) {
imports.push(t.importDeclaration([], t.stringLiteral(`${target.toLowerCase()}.${style}`)))
const cssTarget = `${packagesPath + curr}/${curr}`;
imports.push(t.importDeclaration([], t.stringLiteral(`${cssTarget}.${style}`)))
}

@@ -38,2 +36,21 @@ return newSpecifiers.concat(imports);

/**
* 根据参数改变引用文件类型
*/
function getTarget(pkgName, pkgPath, isSourceCode) {
let target = pkgPath;
if(isSourceCode) {
const isLocale = isLocaleExtra(curr);
const isExportFunc = isExportFuncExtra(curr);
const localePath = join(pkgPath, '..', 'locale');
const exportFuncTarget = `${pkgPath}/${pkgName}/_${pkgName}.js`;
const sourceFile = `${pkgPath + pkgName}/${pkgName}.vue`;
target = isLocale? localePath: isExportFunc? exportFuncTarget: sourceFile;
}else{
target = `${target + pkgName}/${pkgName}.js`;
}
console.log('\n\n\n\n\n\nisSourceCode,', isSourceCode, target);
return target;
}
module.exports = function() {

@@ -45,2 +62,3 @@

if(!opts.libraryName) opts.libraryName = '@nutui/nutui2';
if(!opts.sourceCode) opts.sourceCode = false;
const {style} = opts;

@@ -54,3 +72,3 @@ if(style) opts.style = style === 'scss'? 'scss': 'css';

if(value === opts.libraryName && specifiers && specifiers.length) {
const spes = specifiers.filter(specifier => specifier.type === 'ImportSpecifier').map(specifier => specifier.local.name);
const spes = specifiers.filter(specifier => specifier.type === 'ImportSpecifier').map(specifier => specifier.local.name.toLowerCase());
if(spes.length) {

@@ -57,0 +75,0 @@ path.replaceWithMultiple(genImportDeclaration(spes, opts))

{
"name": "@nutui/babel-plugin-separate-import",
"version": "0.1.5",
"version": "0.1.6",
"description": "按需构建nutui2.0的组件,减小打包体积",

@@ -18,4 +18,4 @@ "main": "index.js",

"nutui",
"import"
"import"
]
}

@@ -25,3 +25,2 @@ ### @nutui/babel-plugin-separate-import

["@nutui/babel-plugin-separate-import", {
"libraryName": "@nutui/nutui"
"style": "css"

@@ -28,0 +27,0 @@ }]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc