| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import fs from 'node:fs'
- import path from 'node:path'
- import { type Plugin, defineConfig } from 'vite-plus'
- import vue from '@vitejs/plugin-vue'
- import { spawnSync } from 'node:child_process'
- const commit = spawnSync('git', ['rev-parse', '--short=7', 'HEAD'])
- .stdout.toString()
- .trim()
- export default defineConfig({
- plugins: [
- vue({
- script: {
- fs: {
- fileExists: fs.existsSync,
- readFile: file => fs.readFileSync(file, 'utf-8'),
- },
- },
- }),
- copyVuePlugin(),
- ],
- define: {
- __COMMIT__: JSON.stringify(commit),
- __VUE_PROD_DEVTOOLS__: JSON.stringify(true),
- },
- optimizeDeps: {
- exclude: ['@vue/repl'],
- },
- })
- function copyVuePlugin(): Plugin {
- return {
- name: 'copy-vue',
- generateBundle() {
- const copyFile = (file: string) => {
- const filePath = path.resolve(__dirname, '../../packages', 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'),
- })
- }
- copyFile(`vue/dist/vue.esm-browser.js`)
- copyFile(`vue/dist/vue.esm-browser.prod.js`)
- copyFile(`vue/dist/vue.runtime.esm-browser.js`)
- copyFile(`vue/dist/vue.runtime.esm-browser.prod.js`)
- copyFile(`vue/dist/vue.runtime-with-vapor.esm-browser.js`)
- copyFile(`vue/dist/vue.runtime-with-vapor.esm-browser.prod.js`)
- copyFile(`server-renderer/dist/server-renderer.esm-browser.js`)
- },
- }
- }
|