fix(vite-plugin): 按需打包插件支持更多自定义包名 (#276)
This commit is contained in:
parent
77b68bea18
commit
598d173029
|
@ -1,14 +1,18 @@
|
||||||
{
|
{
|
||||||
"name": "@opentiny/vue-vite-import",
|
"name": "@opentiny/vue-vite-import",
|
||||||
"version": "1.1.0",
|
"version": "1.1.2",
|
||||||
"description": "A TinyVue vite import plugin",
|
"description": "A TinyVue vite import plugin",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"module": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "tsc -w -p .",
|
"dev": "tsc -w -p .",
|
||||||
"build": "tsc && npx tsc --outDir dist",
|
"build": "tsc && npx tsc --outDir dist",
|
||||||
"prepublishOnly": "npm run build"
|
"prepublishOnly": "npm run build"
|
||||||
},
|
},
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"author": "Tiny Vue Team",
|
"author": "Tiny Vue Team",
|
||||||
|
|
|
@ -41,7 +41,7 @@ export default function vitePluginBabelImport(
|
||||||
return {
|
return {
|
||||||
name: '@opentiny/vue-vite-import',
|
name: '@opentiny/vue-vite-import',
|
||||||
transform(code, id) {
|
transform(code, id) {
|
||||||
const isCheckMode = mode && /@opentiny\/vue-.+?\/lib\/index.js$/.test(id)
|
const isCheckMode = mode && /@opentiny\/vue-.+?\/lib\/index.js$/.test(id) && code.includes(`./${mode}`)
|
||||||
// 不处理node_modules内的依赖
|
// 不处理node_modules内的依赖
|
||||||
if (/\.(?:[jt]sx?|vue)$/.test(id) && !/(node_modules)/.test(id)) {
|
if (/\.(?:[jt]sx?|vue)$/.test(id) && !/(node_modules)/.test(id)) {
|
||||||
return {
|
return {
|
||||||
|
@ -133,11 +133,7 @@ const transformDefaultImport = (matchRes: string, opt: PluginInnerOption) => {
|
||||||
return `import ${matchRes} from '${importName}'`
|
return `import ${matchRes} from '${importName}'`
|
||||||
}
|
}
|
||||||
|
|
||||||
const compRegExpMap = {
|
const getCompRegExp = (libraryName: any) => new RegExp(`import\\s+?{([\\w ,\\s]+)}\\s+?from\\s+?('|")${libraryName}('|")`, 'g')
|
||||||
'@opentiny/vue': /import\s+?{([\w ,\s]+)}\s+?from\s+?('|")@opentiny\/vue('|")/g,
|
|
||||||
'@opentiny/vue-icon':
|
|
||||||
/import\s+?{*([\w ,\s]+)}*\s+?from\s+?('|")@opentiny\/vue-icon('|")/g
|
|
||||||
}
|
|
||||||
|
|
||||||
function transformCode(
|
function transformCode(
|
||||||
code: string,
|
code: string,
|
||||||
|
@ -146,7 +142,7 @@ function transformCode(
|
||||||
let resultCode = code
|
let resultCode = code
|
||||||
|
|
||||||
plgOptions.forEach(opt => {
|
plgOptions.forEach(opt => {
|
||||||
const compRegexp = compRegExpMap[(opt.libraryName as '@opentiny/vue')]
|
const compRegexp = getCompRegExp(opt.libraryName)
|
||||||
if (compRegexp && compRegexp.test(resultCode)) {
|
if (compRegexp && compRegexp.test(resultCode)) {
|
||||||
const newCode = resultCode.replace(compRegexp, (_all, matchRes): string => {
|
const newCode = resultCode.replace(compRegexp, (_all, matchRes): string => {
|
||||||
if (_all.includes('{')) {
|
if (_all.includes('{')) {
|
||||||
|
|
Loading…
Reference in New Issue