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