vite-plugin-lazy-import
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -110,12 +110,9 @@ (function (global, factory) { | ||
} | ||
function transformImport(id, syntaxCode, resOpts) { | ||
var importVariables = syntaxCode.split(',').map(function (name) { | ||
return name.trim(); | ||
}); | ||
function transformImport(id, exports, resOpts) { | ||
var importCodes = []; | ||
importVariables.forEach(function (name) { | ||
var asRest = name.match(/([a-zA-Z0-9_]+)\s+as\s+([a-zZ-Z0-9_]+)/); | ||
var importName = name; | ||
if (asRest) { | ||
importName = asRest[1]; | ||
exports.forEach(function (item) { | ||
var importName = item.ln || item.n; | ||
var variableCode = item.n; | ||
if (item.ln !== item.n) { | ||
variableCode = "".concat(importName, " as ").concat(item.n); | ||
} | ||
@@ -132,3 +129,3 @@ var jsPath = ''; | ||
var dirName = _xeUtils["default"].kebabCase(importName); | ||
jsPath = "import { ".concat(name, " } from \"").concat(resOpts.libraryName, "/").concat(libDir, "/").concat(dirName, "/index.js\""); | ||
jsPath = "import { ".concat(variableCode, " } from \"").concat(resOpts.libraryName, "/").concat(libDir, "/").concat(dirName, "/index.js\""); | ||
stylePath = "import \"".concat(resOpts.libraryName, "/").concat(libDir, "/").concat(dirName, "/style.").concat(extName, "\""); | ||
@@ -144,6 +141,6 @@ if (resOpts.resolve) { | ||
if (_xeUtils["default"].isString(fromRest)) { | ||
jsPath = "import { ".concat(name, " } from \"").concat(fromRest, "\""); | ||
jsPath = "import { ".concat(variableCode, " } from \"").concat(fromRest, "\""); | ||
} else { | ||
if (fromRest.jsPath) { | ||
jsPath = "import { ".concat(name, " } from \"").concat(fromRest.jsPath, "\""); | ||
jsPath = "import { ".concat(variableCode, " } from \"").concat(fromRest.jsPath, "\""); | ||
} | ||
@@ -187,8 +184,7 @@ if (fromRest.stylePath) { | ||
} | ||
var importRE = new RegExp("^import\\s+\\{(\\s+)?([a-zA-Z0-9,_\\s]+)\\}(\\s+)?from\\s+('|\")".concat(resOpts.libraryName, "('|\")")); | ||
var matchRest = restCode.slice(syntaxItem.ss, syntaxItem.se).replace(/\n/g, ' ').match(importRE); | ||
if (!matchRest) { | ||
var exports = (0, _esModuleLexer.parse)(restCode.slice(syntaxItem.ss, syntaxItem.se).replace('import', 'export'))[1]; | ||
if (!exports.length) { | ||
return; | ||
} | ||
var importCode = transformImport(id, matchRest[2], resOpts); | ||
var importCode = transformImport(id, exports, resOpts); | ||
isTransform = true; | ||
@@ -195,0 +191,0 @@ restCode = "".concat(restCode.slice(0, syntaxItem.ss)).concat(importCode).concat(restCode.slice(syntaxItem.se)); |
{ | ||
"name": "vite-plugin-lazy-import", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Used for vite Lazy import js and style", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
26556
587