2021-03-28 13:35:45 +08:00
|
|
|
import fs from 'fs'
|
|
|
|
import path from 'path'
|
|
|
|
import { defineConfig, Plugin } from 'vite'
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
2023-09-21 20:25:32 +08:00
|
|
|
import { execaSync } from 'execa'
|
2021-03-29 14:07:04 +08:00
|
|
|
|
2023-10-20 17:31:50 +08:00
|
|
|
const commit = execaSync('git', ['rev-parse', '--short=7', 'HEAD']).stdout
|
2021-03-28 13:35:45 +08:00
|
|
|
|
|
|
|
export default defineConfig({
|
2023-04-14 17:27:50 +08:00
|
|
|
plugins: [
|
|
|
|
vue({
|
|
|
|
script: {
|
2023-07-10 00:18:59 +08:00
|
|
|
defineModel: true,
|
2023-04-14 17:27:50 +08:00
|
|
|
fs: {
|
|
|
|
fileExists: fs.existsSync,
|
|
|
|
readFile: file => fs.readFileSync(file, 'utf-8')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
copyVuePlugin()
|
|
|
|
],
|
2021-03-29 14:07:04 +08:00
|
|
|
define: {
|
2021-09-22 21:07:08 +08:00
|
|
|
__COMMIT__: JSON.stringify(commit),
|
|
|
|
__VUE_PROD_DEVTOOLS__: JSON.stringify(true)
|
2021-03-29 14:07:04 +08:00
|
|
|
},
|
2021-03-28 13:35:45 +08:00
|
|
|
optimizeDeps: {
|
2021-09-07 06:02:27 +08:00
|
|
|
exclude: ['@vue/repl']
|
2021-03-28 13:35:45 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
function copyVuePlugin(): Plugin {
|
|
|
|
return {
|
|
|
|
name: 'copy-vue',
|
2021-03-29 14:07:04 +08:00
|
|
|
generateBundle() {
|
2022-05-25 12:57:28 +08:00
|
|
|
const copyFile = (file: string) => {
|
|
|
|
const filePath = path.resolve(__dirname, file)
|
|
|
|
const basename = path.basename(file)
|
|
|
|
if (!fs.existsSync(filePath)) {
|
|
|
|
throw new Error(
|
|
|
|
`${basename} not built. ` +
|
|
|
|
`Run "nr build vue -f esm-browser" first.`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
this.emitFile({
|
|
|
|
type: 'asset',
|
|
|
|
fileName: basename,
|
|
|
|
source: fs.readFileSync(filePath, 'utf-8')
|
|
|
|
})
|
2021-03-28 13:35:45 +08:00
|
|
|
}
|
2022-05-25 12:57:28 +08:00
|
|
|
|
|
|
|
copyFile(`../vue/dist/vue.runtime.esm-browser.js`)
|
|
|
|
copyFile(`../server-renderer/dist/server-renderer.esm-browser.js`)
|
2021-03-28 13:35:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|