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

fix: 修复unpkg依赖 #188

Merged
merged 7 commits into from
Dec 26, 2023
Merged
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
4 changes: 2 additions & 2 deletions packages/blockToWebComponentTemplate/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ const config = {

export default defineConfig(({ command, mode }) => {
if (command !== 'build' || mode !== 'block') {
return
return config
}

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

config.publicDir = false

Expand Down
1 change: 1 addition & 0 deletions packages/common/js/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const PROD = import.meta.env.PROD
export const BASE_URL = import.meta.env.BASE_URL
export const VITE_ORIGIN = import.meta.env.VITE_ORIGIN
export const VITE_API_MOCK = import.meta.env.VITE_API_MOCK
export const VITE_CDN_DOMAIN = import.meta.env.VITE_CDN_DOMAIN

export const isMock = VITE_API_MOCK === 'mock'

Expand Down
1 change: 1 addition & 0 deletions packages/design-core/.env.alpha
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# alpha mode, used by the "build:alpha" script

NODE_ENV=production
VITE_CDN_DOMAIN=https://npm.onmicrosoft.cn
# VITE_ORIGIN=
1 change: 1 addition & 0 deletions packages/design-core/.env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# development mode, used by the "vite" command

NODE_ENV=development
VITE_CDN_DOMAIN=https://npm.onmicrosoft.cn
# request data via alpha service
# VITE_ORIGIN=
1 change: 1 addition & 0 deletions packages/design-core/.env.prod
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# prod mode, used by the "build:prod" script

NODE_ENV=production
VITE_CDN_DOMAIN=https://npm.onmicrosoft.cn
#VITE_ORIGIN=
2 changes: 1 addition & 1 deletion packages/design-core/canvas.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://registry.npmmirror.com/@opentiny/vue-theme/3.10/files/index.css" rel="stylesheet" />
<link href="https://npm.onmicrosoft.cn/@opentiny/vue-theme@3.11/index.css" rel="stylesheet" />
<style type="text/css">
.loading-warp {
display: flex;
Expand Down
8 changes: 4 additions & 4 deletions packages/design-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@
"@opentiny/tiny-engine-toolbar-setting": "workspace:^1.0.0",
"@opentiny/tiny-engine-utils": "workspace:^1.0.0",
"@opentiny/tiny-engine-webcomponent-core": "workspace:^1.0.0",
"@opentiny/vue": "~3.10.0",
"@opentiny/vue-design-smb": "~3.10.0",
"@opentiny/vue-renderless": "~3.10.0",
"@opentiny/vue-theme": "~3.10.0",
"@opentiny/vue": "~3.11.0",
"@opentiny/vue-design-smb": "~3.11.0",
"@opentiny/vue-renderless": "~3.11.0",
"@opentiny/vue-theme": "~3.11.0",
"@vue/babel-plugin-jsx": "1.1.1",
"@vue/repl": "^2.9.0",
"@vueuse/core": "^9.6.0",
Expand Down
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://unpkg.com/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://unpkg.com/element-plus@2.4.2/dist/index.css",
"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",
"dependencies": null,
"exportName": "ElInput"
},
Expand Down Expand Up @@ -300,8 +300,8 @@
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://unpkg.com/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://unpkg.com/element-plus@2.4.2/dist/index.css",
"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",
"dependencies": null,
"exportName": "ElButton"
},
Expand Down Expand Up @@ -621,8 +621,8 @@
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://unpkg.com/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://unpkg.com/element-plus@2.4.2/dist/index.css",
"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",
"dependencies": null,
"exportName": "ElForm"
},
Expand Down Expand Up @@ -1078,8 +1078,8 @@
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://unpkg.com/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://unpkg.com/element-plus@2.4.2/dist/index.css",
"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",
"dependencies": null,
"exportName": "ElFormItem"
},
Expand Down Expand Up @@ -1428,8 +1428,8 @@
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://unpkg.com/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://unpkg.com/element-plus@2.4.2/dist/index.css",
"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",
"dependencies": null,
"exportName": "ElTable"
},
Expand Down Expand Up @@ -2664,8 +2664,8 @@
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://unpkg.com/element-plus@2.4.2/dist/index.full.mjs",
"css": "https://unpkg.com/element-plus@2.4.2/dist/index.css",
"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",
"dependencies": null,
"exportName": "ElTableColumn"
},
Expand Down
42 changes: 21 additions & 21 deletions packages/design-core/src/preview/src/preview/importMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@
// import { hyphenate } from '@vue/shared'

import { getSearchParams } from './http'
import { VITE_CDN_DOMAIN } from '@opentiny/tiny-engine-common/js/environments'

const importMap = {}

const opentinyVueVersion = '~3.11'

const tinyVue3Imports = {
// 推荐之后统一使用@opentiny/vue去引入依赖,兼容后续录入的组件来源于tiny-vue
'@opentiny/vue': 'https://registry.npmmirror.com/@opentiny/vue/3.11/files/runtime/tiny-vue.mjs',
'@opentiny/vue-icon': 'https://registry.npmmirror.com/@opentiny/vue/3.11/files/runtime/tiny-vue-icon.mjs',
'@opentiny/vue-common': 'https://registry.npmmirror.com/@opentiny/vue/3.11/files/runtime/tiny-vue-common.mjs',
'@opentiny/vue-locale': 'https://registry.npmmirror.com/@opentiny/vue/3.11/files/runtime/tiny-vue-locale.mjs',
'@opentiny/vue-renderless/': 'https://esm.sh/@opentiny/vue-renderless@3.11/?raw'
'@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}/`
}

importMap.imports = {
vue: 'https://registry.npmmirror.com/vue/3.2.36/files/dist/vue.esm-browser.js',
'vue/server-renderer':
'https://registry.npmmirror.com/vue/server-renderer/3.2.36/files/dist/server-renderer.esm-browser.js',
'vue-i18n': 'https://registry.npmmirror.com/vue-i18n/9.2.0/files/dist/vue-i18n.esm-browser.js',
'vue-router': 'https://registry.npmmirror.com/vue-router/4.0.16/files/dist/vue-router.esm-browser.js',
'@vue/devtools-api': 'https://esm.sh/@vue/devtools-api@6.1.4/lib/esm/index.js?raw',
'@vueuse/core': 'https://registry.npmmirror.com/@vueuse/core/9.6.0/files/index.mjs',
'@vueuse/shared': 'https://registry.npmmirror.com/@vueuse/shared/9.6.0/files/index.mjs',
axios: 'https://registry.npmmirror.com/axios/1.0.0-alpha.1/files/dist/esm/axios.js',
'axios-mock-adapter': 'https://registry.npmmirror.com/axios-mock-adapter/1.21.1/files/dist/axios-mock-adapter.js',
'@opentiny/tiny-engine-webcomponent-core':
'https://registry.npmmirror.com/@opentiny/tiny-engine-webcomponent-core/1/files/dist/tiny-engine-webcomponent-core.es.js',
'@opentiny/tiny-engine-i18n-host':
'https://registry.npmmirror.com/@opentiny/tiny-engine-i18n-host/1/files/dist/tiny-engine-i18n-host.es.js',
'vue-demi': 'https://registry.npmmirror.com/vue-demi/0.13.11/files/lib/index.mjs',
pinia: 'https://registry.npmmirror.com/pinia/2.0.22/files/dist/pinia.esm-browser.js',
vue: `${VITE_CDN_DOMAIN}/vue@3.2.36/dist/vue.runtime.esm-browser.js`,
'vue/server-renderer': `${VITE_CDN_DOMAIN}/@vue/server-renderer@3.2.36/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-alpha.1/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/tiny-engine-i18n-host.es.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`,
...tinyVue3Imports,
...getSearchParams().scripts
}
Expand Down
4 changes: 2 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,5 @@ function addCss(href) {
link.setAttribute('href', href)
document.head.appendChild(link)
}
addCss('https://registry.npmmirror.com/@opentiny/vue-theme/3.10/files/index.css')
addCss('https://registry.npmmirror.com/@opentiny/vue-theme-mobile/3.10/files/index.css')
addCss('https://npm.onmicrosoft.cn/@opentiny/vue-theme@3.11/index.css')
addCss('https://npm.onmicrosoft.cn/@opentiny/vue-theme-mobile@3.11/index.css')
66 changes: 33 additions & 33 deletions packages/design-core/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'

import path from 'path'
import vue from '@vitejs/plugin-vue'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
Expand All @@ -12,6 +13,7 @@ import { importmapPlugin } from './scripts/externalDeps'
import visualizer from 'rollup-plugin-visualizer'

const origin = 'http://localhost:9090/'

const config = {
base: './',
publicDir: path.resolve(__dirname, './public'),
Expand Down Expand Up @@ -118,6 +120,7 @@ const config = {
}
}
}

const importMapVersions = {
prettier: '2.7.1',
vue: '3',
Expand Down Expand Up @@ -175,11 +178,6 @@ const devAlias = {
'@opentiny/tiny-engine-builtin-component': path.resolve(__dirname, '../builtinComponent/index.js')
}

const devVueAlias = {
find: /^vue$/,
replacement: `https://registry.npmmirror.com/vue/${importMapVersions.vue}/files/dist/vue.runtime.esm-browser.js`
}

const prodAlias = {
'@opentiny/tiny-engine-theme': path.resolve(
__dirname,
Expand All @@ -191,29 +189,8 @@ const commonAlias = {
'@opentiny/tiny-engine-app-addons': path.resolve(__dirname, './config/addons.js')
}

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

vue: `https://unpkg.com/vue@${importMapVersions.vue}/dist/vue.runtime.esm-browser.js`,
'@opentiny/vue': `https://unpkg.com/@opentiny/vue@${importMapVersions.tinyVue}/runtime/tiny-vue.mjs`,
'@opentiny/vue-icon': `https://unpkg.com/@opentiny/vue@${importMapVersions.tinyVue}/runtime/tiny-vue-icon.mjs`,
'@opentiny/vue-common': `https://unpkg.com/@opentiny/vue@${importMapVersions.tinyVue}/runtime/tiny-vue-common.mjs`,
'@opentiny/vue-locale': `https://unpkg.com/@opentiny/vue@${importMapVersions.tinyVue}/runtime/tiny-vue-locale.mjs`,
'@opentiny/vue-design-smb': `https://unpkg.com/@opentiny/vue-design-smb@${importMapVersions.tinyVue}/index.js`,
'@opentiny/vue-theme/theme-tool': `https://unpkg.com/@opentiny/vue-theme@${importMapVersions.tinyVue}/theme-tool`,
'@opentiny/vue-theme/theme': `https://unpkg.com/@opentiny/vue-theme@${importMapVersions.tinyVue}/theme`
}
}

const importMapStyles = [`https://unpkg.com/@opentiny/vue-theme@${importMapVersions.tinyVue}/index.css`]

export default defineConfig(({ command, mode }) => {
const { VITE_CDN_DOMAIN } = loadEnv(mode, process.cwd(), '')
const monacoPublicPath = {
local: 'editor/monaco-workers',
alpha: 'https://tinyengine-assets.obs.cn-north-4.myhuaweicloud.com/files/monaco-assets',
Expand Down Expand Up @@ -251,6 +228,11 @@ 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`
}

config.resolve.alias = [
devVueAlias,
...Object.entries({ ...commonAlias, ...devAlias }).map(([find, replacement]) => ({
Expand All @@ -270,11 +252,29 @@ export default defineConfig(({ command, mode }) => {
}
}

config.plugins.push(
monacoEditorPluginInstance,
htmlPlugin(mode),
command === 'build' && importmapPlugin(importmap, importMapStyles)
)
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.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`,
'@opentiny/vue-theme/theme': `${VITE_CDN_DOMAIN}/@opentiny/vue-theme@${importMapVersions.tinyVue}/theme`
}
}

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

config.plugins.push(monacoEditorPluginInstance, htmlPlugin(mode), importmapPlugin(importmap, importMapStyles))

return config
})