Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chore): support npmmirror cdn #489

Draft
wants to merge 1 commit into
base: v1.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/blockToWebComponentTemplate/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default defineConfig(({ command, mode }) => {
}

const vuePluginConfig = {}
const styleLinks = ['https://npm.onmicrosoft.cn/@opentiny/vue-theme@3.14/index.css']
const styleLinks = ['https://registry.npmmirror.com/@opentiny/vue-theme/3.14/files/index.css']

config.publicDir = false

Expand Down
3 changes: 2 additions & 1 deletion packages/design-core/.env.alpha
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# alpha mode, used by the "build:alpha" script

NODE_ENV=production
VITE_CDN_DOMAIN=https://npm.onmicrosoft.cn
VITE_CDN_DOMAIN=https://registry.npmmirror.com
VITE_CDN_TYPE=npmmirror
VITE_LOCAL_IMPORT_MAPS=false
VITE_LOCAL_BUNDLE_DEPS=false
# VITE_ORIGIN=
Expand Down
4 changes: 3 additions & 1 deletion packages/design-core/.env.development
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# development mode, used by the "vite" command

NODE_ENV=development
VITE_CDN_DOMAIN=https://npm.onmicrosoft.cn
VITE_CDN_DOMAIN=https://registry.npmmirror.com
VITE_CDN_TYPE=npmmirror

VITE_LOCAL_IMPORT_MAPS=false
VITE_LOCAL_BUNDLE_DEPS=false
# request data via alpha service
Expand Down
3 changes: 2 additions & 1 deletion packages/design-core/.env.prod
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# prod mode, used by the "build:prod" script

NODE_ENV=production
VITE_CDN_DOMAIN=https://npm.onmicrosoft.cn
VITE_CDN_DOMAIN=https://registry.npmmirror.com
VITE_CDN_TYPE=npmmirror
VITE_LOCAL_IMPORT_MAPS=false
VITE_LOCAL_BUNDLE_DEPS=false
#VITE_ORIGIN=
24 changes: 12 additions & 12 deletions packages/design-core/public/mock/bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.css",
"script": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.full.mjs",
"css": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.css",
"dependencies": null,
"exportName": "ElInput"
},
Expand Down Expand Up @@ -300,8 +300,8 @@
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.css",
"script": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.full.mjs",
"css": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.css",
"dependencies": null,
"exportName": "ElButton"
},
Expand Down Expand Up @@ -621,8 +621,8 @@
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.css",
"script": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.full.mjs",
"css": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.css",
"dependencies": null,
"exportName": "ElForm"
},
Expand Down Expand Up @@ -1078,8 +1078,8 @@
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.css",
"script": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.full.mjs",
"css": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.css",
"dependencies": null,
"exportName": "ElFormItem"
},
Expand Down Expand Up @@ -1428,8 +1428,8 @@
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.css",
"script": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.full.mjs",
"css": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.css",
"dependencies": null,
"exportName": "ElTable"
},
Expand Down Expand Up @@ -2666,8 +2666,8 @@
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://npm.onmicrosoft.cn/element-plus@2.4.2/dist/index.css",
"script": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.full.mjs",
"css": "https://registry.npmmirror.com/element-plus/2.4.2/files/dist/index.css",
"dependencies": null,
"exportName": "ElTableColumn"
},
Expand Down
8 changes: 7 additions & 1 deletion packages/design-core/src/preview/src/preview/importMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ import { VITE_CDN_DOMAIN } from '@opentiny/tiny-engine-controller/js/environment
const importMap = {}

const opentinyVueVersion = '~3.14'
const versionDelimiter = import.meta.env.VITE_CDN_TYPE === 'npmmirror' ? '/' : '@'
const fileDelimiter = import.meta.env.VITE_CDN_TYPE === 'npmmirror' ? '/files' : ''

function replacePlaceholder(v) {
return v.replace('${VITE_CDN_DOMAIN}', VITE_CDN_DOMAIN).replace('${opentinyVueVersion}', opentinyVueVersion)
return v
.replace('${VITE_CDN_DOMAIN}', VITE_CDN_DOMAIN)
.replace('${opentinyVueVersion}', opentinyVueVersion)
.replace('${versionDelimiter}', versionDelimiter)
.replace('${fileDelimiter}', fileDelimiter)
}

importMap.imports = {
Expand Down
38 changes: 19 additions & 19 deletions packages/design-core/src/preview/src/preview/importMap.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"imports": {
"vue": "${VITE_CDN_DOMAIN}/vue@3.4.23/dist/vue.runtime.esm-browser.js",
"vue/server-renderer": "${VITE_CDN_DOMAIN}/@vue/server-renderer@3.4.23/dist/server-renderer.esm-browser.js",
"vue-i18n": "${VITE_CDN_DOMAIN}/vue-i18n@9.2.0-beta.36/dist/vue-i18n.esm-browser.js",
"vue-router": "${VITE_CDN_DOMAIN}/vue-router@4.0.16/dist/vue-router.esm-browser.js",
"@vue/devtools-api": "${VITE_CDN_DOMAIN}/@vue/devtools-api@6.5.1/lib/esm/index.js",
"@vueuse/core": "${VITE_CDN_DOMAIN}/@vueuse/core@9.6.0/index.mjs",
"@vueuse/shared": "${VITE_CDN_DOMAIN}/@vueuse/shared@9.6.0/index.mjs",
"axios": "${VITE_CDN_DOMAIN}/axios@1.0.0/dist/esm/axios.js",
"axios-mock-adapter": "${VITE_CDN_DOMAIN}/axios-mock-adapter@1.21.1/dist/axios-mock-adapter.js",
"@opentiny/tiny-engine-webcomponent-core": "${VITE_CDN_DOMAIN}/@opentiny/tiny-engine-webcomponent-core@1/dist/tiny-engine-webcomponent-core.es.js",
"@opentiny/tiny-engine-i18n-host": "${VITE_CDN_DOMAIN}/@opentiny/tiny-engine-i18n-host@1/dist/lowcode-design-i18n-host.es.js",
"@opentiny/tiny-engine-builtin-component": "${VITE_CDN_DOMAIN}/@opentiny/tiny-engine-builtin-component@1/dist/index.js",
"vue-demi": "${VITE_CDN_DOMAIN}/vue-demi@0.13.11/lib/index.mjs",
"pinia": "${VITE_CDN_DOMAIN}/pinia@2.0.22/dist/pinia.esm-browser.js",
"@opentiny/vue": "${VITE_CDN_DOMAIN}/@opentiny/vue@${opentinyVueVersion}/runtime/tiny-vue.mjs",
"@opentiny/vue-icon": "${VITE_CDN_DOMAIN}/@opentiny/vue@${opentinyVueVersion}/runtime/tiny-vue-icon.mjs",
"@opentiny/vue-common": "${VITE_CDN_DOMAIN}/@opentiny/vue@${opentinyVueVersion}/runtime/tiny-vue-common.mjs",
"@opentiny/vue-locale": "${VITE_CDN_DOMAIN}/@opentiny/vue@${opentinyVueVersion}/runtime/tiny-vue-locale.mjs",
"@opentiny/vue-renderless/": "${VITE_CDN_DOMAIN}/@opentiny/vue-renderless@${opentinyVueVersion}/"
"vue": "${VITE_CDN_DOMAIN}/vue${versionDelimiter}3.4.23${fileDelimiter}/dist/vue.runtime.esm-browser.js",
"vue/server-renderer": "${VITE_CDN_DOMAIN}/@vue/server-renderer${versionDelimiter}3.4.23${fileDelimiter}/dist/server-renderer.esm-browser.js",
"vue-i18n": "${VITE_CDN_DOMAIN}/vue-i18n${versionDelimiter}9.2.0-beta.36${fileDelimiter}/dist/vue-i18n.esm-browser.js",
"vue-router": "${VITE_CDN_DOMAIN}/vue-router${versionDelimiter}4.0.16${fileDelimiter}/dist/vue-router.esm-browser.js",
"@vue/devtools-api": "${VITE_CDN_DOMAIN}/@vue/devtools-api${versionDelimiter}6.5.1${fileDelimiter}/lib/esm/index.js",
"@vueuse/core": "${VITE_CDN_DOMAIN}/@vueuse/core${versionDelimiter}9.6.0${fileDelimiter}/index.mjs",
"@vueuse/shared": "${VITE_CDN_DOMAIN}/@vueuse/shared${versionDelimiter}9.6.0${fileDelimiter}/index.mjs",
"axios": "${VITE_CDN_DOMAIN}/axios${versionDelimiter}1.0.0${fileDelimiter}/dist/esm/axios.js",
"axios-mock-adapter": "${VITE_CDN_DOMAIN}/axios-mock-adapter${versionDelimiter}1.21.1${fileDelimiter}/dist/axios-mock-adapter.js",
"@opentiny/tiny-engine-webcomponent-core": "${VITE_CDN_DOMAIN}/@opentiny/tiny-engine-webcomponent-core${versionDelimiter}1${fileDelimiter}/dist/tiny-engine-webcomponent-core.es.js",
"@opentiny/tiny-engine-i18n-host": "${VITE_CDN_DOMAIN}/@opentiny/tiny-engine-i18n-host${versionDelimiter}1${fileDelimiter}/dist/lowcode-design-i18n-host.es.js",
"@opentiny/tiny-engine-builtin-component": "${VITE_CDN_DOMAIN}/@opentiny/tiny-engine-builtin-component${versionDelimiter}1${fileDelimiter}/dist/index.js",
"vue-demi": "${VITE_CDN_DOMAIN}/vue-demi${versionDelimiter}0.13.11${fileDelimiter}/lib/index.mjs",
"pinia": "${VITE_CDN_DOMAIN}/pinia${versionDelimiter}2.0.22${fileDelimiter}/dist/pinia.esm-browser.js",
"@opentiny/vue": "${VITE_CDN_DOMAIN}/@opentiny/vue${versionDelimiter}${opentinyVueVersion}${fileDelimiter}/runtime/tiny-vue.mjs",
"@opentiny/vue-icon": "${VITE_CDN_DOMAIN}/@opentiny/vue${versionDelimiter}${opentinyVueVersion}${fileDelimiter}/runtime/tiny-vue-icon.mjs",
"@opentiny/vue-common": "${VITE_CDN_DOMAIN}/@opentiny/vue${versionDelimiter}${opentinyVueVersion}${fileDelimiter}/runtime/tiny-vue-common.mjs",
"@opentiny/vue-locale": "${VITE_CDN_DOMAIN}/@opentiny/vue${versionDelimiter}${opentinyVueVersion}${fileDelimiter}/runtime/tiny-vue-locale.mjs",
"@opentiny/vue-renderless/": "${VITE_CDN_DOMAIN}/@opentiny/vue-renderless${versionDelimiter}${opentinyVueVersion}${fileDelimiter}/"
}
}
8 changes: 7 additions & 1 deletion packages/design-core/src/preview/src/preview/srcFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ import storesHelperJS from './srcFiles/storesHelper.js?raw'

const srcFiles = {}

const versionDelimiter = import.meta.env.VITE_CDN_TYPE === 'npmmirror' ? '/' : '@'
const fileDelimiter = import.meta.env.VITE_CDN_TYPE === 'npmmirror' ? '/files' : ''

srcFiles['App.vue'] = appVue
srcFiles['Main.vue'] = mainVue
srcFiles['constant.js'] = constantJS
srcFiles['app.js'] = appJS.replace(/VITE_CDN_DOMAIN/g, import.meta.env.VITE_CDN_DOMAIN)
srcFiles['app.js'] = appJS
.replace(/VITE_CDN_DOMAIN/g, import.meta.env.VITE_CDN_DOMAIN)
.replaceAll('${versionDelimiter}', versionDelimiter)
.replaceAll('${fileDelimiter}', fileDelimiter)
srcFiles['injectGlobal.js'] = injectGlobalJS
srcFiles['lowcode.js'] = lowcodeJS
srcFiles['dataSourceMap.js'] = dataSourceMapJS
Expand Down
5 changes: 3 additions & 2 deletions packages/design-core/src/preview/src/preview/srcFiles/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ function addCss(href) {
link.setAttribute('href', href)
document.head.appendChild(link)
}
addCss('VITE_CDN_DOMAIN/@opentiny/[email protected]/index.css')
addCss('VITE_CDN_DOMAIN/@opentiny/[email protected]/index.css')

addCss('VITE_CDN_DOMAIN/@opentiny/vue-theme${versionDelimiter}3.14${fileDelimiter}/index.css')
addCss('VITE_CDN_DOMAIN/@opentiny/vue-theme-mobile${versionDelimiter}3.14${fileDelimiter}/index.css')
70 changes: 45 additions & 25 deletions packages/design-core/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,48 @@ const commonAlias = {
'@opentiny/tiny-engine-app-addons': path.resolve(__dirname, './config/addons.js')
}

const getImportMaps = (cdnLink, command, cdnType) => {
const versionDelimiter = cdnType === 'npmmirror' ? '/' : '@'
const fileDelimiter = cdnType === 'npmmirror' ? '/files' : ''

const importMapStyles = [
`${cdnLink}/@opentiny/vue-theme${versionDelimiter}${importMapVersions.tinyVue}${fileDelimiter}/index.css`
]

const importmap = {
imports: {
prettier: `${cdnLink}/prettier${versionDelimiter}${importMapVersions.prettier}${fileDelimiter}/esm/standalone.mjs`,
'prettier/': `${cdnLink}/prettier${versionDelimiter}${importMapVersions.prettier}${fileDelimiter}/esm/`,
'prettier/parser-typescript': `${cdnLink}/prettier${versionDelimiter}${importMapVersions.prettier}${fileDelimiter}/esm/parser-typescript.mjs`,
'prettier/parser-html': `${cdnLink}/prettier${versionDelimiter}${importMapVersions.prettier}${fileDelimiter}/esm/parser-html.mjs`,
'prettier/parser-postcss': `${cdnLink}/prettier${versionDelimiter}${importMapVersions.prettier}${fileDelimiter}/esm/parser-postcss.mjs`,
'prettier/parser-babel': `${cdnLink}/prettier${versionDelimiter}${importMapVersions.prettier}${fileDelimiter}/esm/parser-babel.mjs`,

vue: `${cdnLink}/vue${versionDelimiter}${importMapVersions.vue}${fileDelimiter}/dist/vue.runtime.esm-browser${
command === 'build' ? '.prod' : ''
}.js`,
'@opentiny/vue': `${cdnLink}/@opentiny/vue${versionDelimiter}${importMapVersions.tinyVue}${fileDelimiter}/runtime/tiny-vue.mjs`,
'@opentiny/vue-icon': `${cdnLink}/@opentiny/vue${versionDelimiter}${importMapVersions.tinyVue}${fileDelimiter}/runtime/tiny-vue-icon.mjs`,
'@opentiny/vue-common': `${cdnLink}/@opentiny/vue${versionDelimiter}${importMapVersions.tinyVue}${fileDelimiter}/runtime/tiny-vue-common.mjs`,
'@opentiny/vue-locale': `${cdnLink}/@opentiny/vue${versionDelimiter}${importMapVersions.tinyVue}${fileDelimiter}/runtime/tiny-vue-locale.mjs`,
'@opentiny/vue-design-smb': `${cdnLink}/@opentiny/vue-design-smb${versionDelimiter}${importMapVersions.tinyVue}${fileDelimiter}/index.js`,
'@opentiny/vue-theme/theme-tool': `${cdnLink}/@opentiny/vue-theme${versionDelimiter}${importMapVersions.tinyVue}${fileDelimiter}/theme-tool.js`,
'@opentiny/vue-theme/theme': `${cdnLink}/@opentiny/vue-theme${versionDelimiter}${importMapVersions.tinyVue}${fileDelimiter}/theme/index.js`
}
}

return {
importMapStyles,
importmap
}
}

export default defineConfig(({ command, mode }) => {
const { VITE_CDN_DOMAIN, VITE_LOCAL_IMPORT_MAPS, VITE_LOCAL_BUNDLE_DEPS } = loadEnv(mode, process.cwd(), '')
const { VITE_CDN_DOMAIN, VITE_LOCAL_IMPORT_MAPS, VITE_LOCAL_BUNDLE_DEPS, VITE_CDN_TYPE } = loadEnv(
mode,
process.cwd(),
''
)
const isLocalImportMap = VITE_LOCAL_IMPORT_MAPS === 'true' // true公共依赖库使用本地打包文件,false公共依赖库使用公共CDN
const isCopyBundleDeps = VITE_LOCAL_BUNDLE_DEPS === 'true' // true bundle里的cdn依赖处理成本地依赖, false 不处理

Expand Down Expand Up @@ -240,7 +280,9 @@ export default defineConfig(({ command, mode }) => {
if (command === 'serve') {
const devVueAlias = {
find: /^vue$/,
replacement: `${VITE_CDN_DOMAIN}/vue@${importMapVersions.vue}/dist/vue.runtime.esm-browser.js`
replacement: `${VITE_CDN_DOMAIN}/vue${VITE_CDN_TYPE === 'npmmirror' ? '/' : ''}${importMapVersions.vue}${
VITE_CDN_TYPE === 'npmmirror' ? '/files' : ''
}/dist/vue.runtime.esm-browser.js`
}

config.resolve.alias = [
Expand All @@ -260,29 +302,7 @@ export default defineConfig(({ command, mode }) => {
}
}

const importmap = {
imports: {
prettier: `${VITE_CDN_DOMAIN}/prettier@${importMapVersions.prettier}/esm/standalone.mjs`,
'prettier/': `${VITE_CDN_DOMAIN}/prettier@${importMapVersions.prettier}/esm/`,
'prettier/parser-typescript': `${VITE_CDN_DOMAIN}/prettier@${importMapVersions.prettier}/esm/parser-typescript.mjs`,
'prettier/parser-html': `${VITE_CDN_DOMAIN}/prettier@${importMapVersions.prettier}/esm/parser-html.mjs`,
'prettier/parser-postcss': `${VITE_CDN_DOMAIN}/prettier@${importMapVersions.prettier}/esm/parser-postcss.mjs`,
'prettier/parser-babel': `${VITE_CDN_DOMAIN}/prettier@${importMapVersions.prettier}/esm/parser-babel.mjs`,

vue: `${VITE_CDN_DOMAIN}/vue@${importMapVersions.vue}/dist/vue.runtime.esm-browser${
command === 'build' ? '.prod' : ''
}.js`,
'@opentiny/vue': `${VITE_CDN_DOMAIN}/@opentiny/vue@${importMapVersions.tinyVue}/runtime/tiny-vue.mjs`,
'@opentiny/vue-icon': `${VITE_CDN_DOMAIN}/@opentiny/vue@${importMapVersions.tinyVue}/runtime/tiny-vue-icon.mjs`,
'@opentiny/vue-common': `${VITE_CDN_DOMAIN}/@opentiny/vue@${importMapVersions.tinyVue}/runtime/tiny-vue-common.mjs`,
'@opentiny/vue-locale': `${VITE_CDN_DOMAIN}/@opentiny/vue@${importMapVersions.tinyVue}/runtime/tiny-vue-locale.mjs`,
'@opentiny/vue-design-smb': `${VITE_CDN_DOMAIN}/@opentiny/vue-design-smb@${importMapVersions.tinyVue}/index.js`,
'@opentiny/vue-theme/theme-tool': `${VITE_CDN_DOMAIN}/@opentiny/vue-theme@${importMapVersions.tinyVue}/theme-tool.js`,
'@opentiny/vue-theme/theme': `${VITE_CDN_DOMAIN}/@opentiny/vue-theme@${importMapVersions.tinyVue}/theme/index.js`
}
}

const importMapStyles = [`${VITE_CDN_DOMAIN}/@opentiny/vue-theme@${importMapVersions.tinyVue}/index.css`]
const { importMapStyles, importmap } = getImportMaps(VITE_CDN_DOMAIN, command, VITE_CDN_TYPE)

config.plugins.push(
monacoEditorPluginInstance,
Expand Down