From 779f52436381c212bef1350438292cf13126a006 Mon Sep 17 00:00:00 2001 From: chilingling Date: Fri, 7 Jun 2024 19:29:56 -0700 Subject: [PATCH 1/2] fix: fix relative path --- designer-demo/vite.config.js | 7 ++++++- .../build/vite-config/src/default-config.js | 17 +++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/designer-demo/vite.config.js b/designer-demo/vite.config.js index 81ff3bf2a4..9d1adf11e5 100644 --- a/designer-demo/vite.config.js +++ b/designer-demo/vite.config.js @@ -1,12 +1,17 @@ import path from 'node:path' +import { fileURLToPath } from 'node:url' import { defineConfig, mergeConfig } from 'vite' import { getDefaultConfig } from '@opentiny/tiny-engine-vite-config' +const __filename = fileURLToPath(import.meta.url) + +const __dirname = path.dirname(__filename) + export default defineConfig((options) => { const extOptions = { iconDirs: [path.resolve(__dirname, './node_modules/@opentiny/tiny-engine/assets/')] } - const defaultConfig = getDefaultConfig(options, extOptions) + const defaultConfig = getDefaultConfig(options, extOptions, __dirname) const devAlias = { '@opentiny/tiny-engine-controller/js': path.resolve(__dirname, '../packages/controller/js'), diff --git a/packages/build/vite-config/src/default-config.js b/packages/build/vite-config/src/default-config.js index ebd6c63236..433790d671 100644 --- a/packages/build/vite-config/src/default-config.js +++ b/packages/build/vite-config/src/default-config.js @@ -12,12 +12,7 @@ import { importmapPlugin } from './externalDeps.js' import visualizerCjs from 'rollup-plugin-visualizer' import { fileURLToPath } from 'node:url' import generateComment from '@opentiny/tiny-engine-vite-plugin-meta-comments' -import { - getBaseUrlFromCli, - copyBundleDeps, - copyPreviewImportMap, - copyLocalImportMap -} from './localCdnFile/index.js' +import { getBaseUrlFromCli, copyBundleDeps, copyPreviewImportMap, copyLocalImportMap } from './localCdnFile/index.js' const monacoEditorPlugin = monacoEditorPluginCjs.default const nodeGlobalsPolyfillPlugin = nodeGlobalsPolyfillPluginCjs.default @@ -79,7 +74,7 @@ const config = { } } }), - vueJsx(), + vueJsx() ], optimizeDeps: { esbuildOptions: { @@ -142,7 +137,7 @@ const importMapVersions = { tinyVue: '~3.14' } -export default defineConfig(({ command = 'serve', mode = 'serve' }, extOptions) => { +export default defineConfig(({ command = 'serve', mode = 'serve' }, extOptions, dirname) => { const { VITE_CDN_DOMAIN = 'https://npm.onmicrosoft.cn', VITE_LOCAL_IMPORT_MAPS, @@ -186,6 +181,12 @@ export default defineConfig(({ command = 'serve', mode = 'serve' }, extOptions) } } + config.build.rollupOptions.input = { + index: path.resolve(dirname, './index.html'), + canvas: path.resolve(dirname, './canvas.html'), + preview: path.resolve(dirname, './preview.html') + } + if (command === 'serve') { const devVueAlias = { find: /^vue$/, From c78fdee212cb2b737bc61ced977c57a62ea31e63 Mon Sep 17 00:00:00 2001 From: chilingling Date: Fri, 7 Jun 2024 20:08:37 -0700 Subject: [PATCH 2/2] fix: read envconfig from extOptions --- designer-demo/{.env.prod => .env.production} | 0 designer-demo/vite.config.js | 10 ++----- .../build/vite-config/src/default-config.js | 29 +++++++------------ 3 files changed, 14 insertions(+), 25 deletions(-) rename designer-demo/{.env.prod => .env.production} (100%) diff --git a/designer-demo/.env.prod b/designer-demo/.env.production similarity index 100% rename from designer-demo/.env.prod rename to designer-demo/.env.production diff --git a/designer-demo/vite.config.js b/designer-demo/vite.config.js index 9d1adf11e5..ebdd4e92c6 100644 --- a/designer-demo/vite.config.js +++ b/designer-demo/vite.config.js @@ -1,17 +1,13 @@ import path from 'node:path' -import { fileURLToPath } from 'node:url' -import { defineConfig, mergeConfig } from 'vite' +import { defineConfig, mergeConfig, loadEnv } from 'vite' import { getDefaultConfig } from '@opentiny/tiny-engine-vite-config' -const __filename = fileURLToPath(import.meta.url) - -const __dirname = path.dirname(__filename) - export default defineConfig((options) => { const extOptions = { + ...loadEnv(options.mode, process.cwd(), ''), iconDirs: [path.resolve(__dirname, './node_modules/@opentiny/tiny-engine/assets/')] } - const defaultConfig = getDefaultConfig(options, extOptions, __dirname) + const defaultConfig = getDefaultConfig(options, extOptions) const devAlias = { '@opentiny/tiny-engine-controller/js': path.resolve(__dirname, '../packages/controller/js'), diff --git a/packages/build/vite-config/src/default-config.js b/packages/build/vite-config/src/default-config.js index 433790d671..eb27c9b539 100644 --- a/packages/build/vite-config/src/default-config.js +++ b/packages/build/vite-config/src/default-config.js @@ -1,4 +1,4 @@ -import { defineConfig, loadEnv } from 'vite' +import { defineConfig } from 'vite' import path from 'path' import vue from '@vitejs/plugin-vue' import monacoEditorPluginCjs from 'vite-plugin-monaco-editor' @@ -88,7 +88,10 @@ const config = { //@vue/repl monaco编辑器需要 resolveFrom: 'cwd', assets: { - from: ['./node_modules/@vue/repl/dist/assets/*'], // worker.js文件以url形式引用不会被esbuild拉起,需要手动复制 + from: [ + './node_modules/@vue/repl/dist/assets/*', + './node_modules/@opentiny/tiny-engine/node_modules/@vue/repl/dist/assets/*' + ], // worker.js文件以url形式引用不会被esbuild拉起,需要手动复制 to: ['./node_modules/.vite/assets'] // 开发态,js文件被缓存在.vite/deps,请求相对路径为.vite/assets }, watch: true @@ -107,10 +110,9 @@ const config = { rollupOptions: { plugins: [nodePolyfill({ include: null })], // 使用@rollup/plugin-inject的默认值{include: null}, 即在所有代码中生效 input: { - index: path.resolve(__dirname, './index.html'), - canvas: path.resolve(__dirname, './canvas.html'), - preview: path.resolve(__dirname, './preview.html'), - previewApp: path.resolve(__dirname, './previewApp.html') + index: path.resolve(process.cwd(), './index.html'), + canvas: path.resolve(process.cwd(), './canvas.html'), + preview: path.resolve(process.cwd(), './preview.html') }, output: { manualChunks: (id) => { @@ -137,12 +139,9 @@ const importMapVersions = { tinyVue: '~3.14' } -export default defineConfig(({ command = 'serve', mode = 'serve' }, extOptions, dirname) => { - const { - VITE_CDN_DOMAIN = 'https://npm.onmicrosoft.cn', - VITE_LOCAL_IMPORT_MAPS, - VITE_LOCAL_BUNDLE_DEPS - } = loadEnv(mode, process.cwd(), '') +export default defineConfig(({ command = 'serve', mode = 'serve' }, extOptions) => { + const { VITE_CDN_DOMAIN = 'https://npm.onmicrosoft.cn', VITE_LOCAL_IMPORT_MAPS, VITE_LOCAL_BUNDLE_DEPS } = extOptions + const isLocalImportMap = VITE_LOCAL_IMPORT_MAPS === 'true' // true公共依赖库使用本地打包文件,false公共依赖库使用公共CDN const isCopyBundleDeps = VITE_LOCAL_BUNDLE_DEPS === 'true' // true bundle里的cdn依赖处理成本地依赖, false 不处理 @@ -181,12 +180,6 @@ export default defineConfig(({ command = 'serve', mode = 'serve' }, extOptions, } } - config.build.rollupOptions.input = { - index: path.resolve(dirname, './index.html'), - canvas: path.resolve(dirname, './canvas.html'), - preview: path.resolve(dirname, './preview.html') - } - if (command === 'serve') { const devVueAlias = { find: /^vue$/,