fix(controller-environment): preserve import.meta.env variable when build controller lib (#380)

This commit is contained in:
chilingling 2024-04-10 01:34:16 -07:00 committed by GitHub
parent 68838ed5f9
commit 0e6d30183a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 5 deletions

View File

@ -15,7 +15,7 @@
],
"exports": {
".": "./dist/index.js",
"./js/": "./js/",
"./js/": "./dist/js/",
"./utils": "./dist/utils.js",
"./adapter": "./dist/adapter.js"
},
@ -36,8 +36,8 @@
"@babel/traverse": "7.18.13",
"@opentiny/tiny-engine-builtin-component": "workspace:*",
"@opentiny/tiny-engine-http": "workspace:*",
"@opentiny/tiny-engine-utils": "workspace:*",
"@opentiny/tiny-engine-i18n-host": "workspace:*",
"@opentiny/tiny-engine-utils": "workspace:*",
"@opentiny/vue": "~3.10.0",
"@opentiny/vue-locale": "~3.10.0",
"@opentiny/vue-renderless": "~3.10.0",
@ -48,6 +48,7 @@
"devDependencies": {
"@vitejs/plugin-vue": "^4.2.3",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"glob": "^10.3.4",
"vite": "^4.3.7"
},
"peerDependencies": {

View File

@ -14,6 +14,12 @@ import { defineConfig } from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { glob } from 'glob'
import { fileURLToPath } from 'node:url'
const jsEntries = glob.sync('./js/**.js').map((file) => {
return [file.slice(0, file.length - path.extname(file).length), fileURLToPath(new URL(file, import.meta.url))]
})
// https://vitejs.dev/config/
export default defineConfig({
@ -21,7 +27,8 @@ export default defineConfig({
publicDir: false,
resolve: {},
define: {
'process.env': {}
'process.env': {},
'import.meta': 'import.meta'
},
build: {
cssCodeSplit: false,
@ -29,14 +36,15 @@ export default defineConfig({
entry: {
index: path.resolve(__dirname, './src/index.js'),
adapter: path.resolve(__dirname, './adapter.js'),
utils: path.resolve(__dirname, './utils.js')
utils: path.resolve(__dirname, './utils.js'),
...Object.fromEntries(jsEntries)
},
name: 'controller',
fileName: (formats, entryName) => `${entryName}.js`,
formats: ['es']
},
rollupOptions: {
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, /^prettier.*/]
external: ['vue', 'vue-i18n', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, /^prettier.*/, /^@babel.*/]
}
}
})