1.代码如下:
import { defineConfig } from 'vite'
import { fileURLToPath, URL } from 'node:url'
import vue from '@vitejs/plugin-vue'
import postCssPxToRem from 'postcss-pxtorem'
import { createHtmlPlugin } from 'vite-plugin-html'
import externalGlobals from "rollup-plugin-external-globals";
export default defineConfig({
base: '/wework-cpic',
plugins: [
vue(),
createHtmlPlugin({
template: './index.html',
inject: {
tags: [
{
injectTo: 'body',
tag: 'script',
attrs: {
src: 'https://res.wx.qq.com/open/js/jweixin-1.2.0.js',
defer: true
}
},
]
}
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
},
server: {
open: false
},
esbuild: {
},
css: {
postcss: {
plugins: [
postCssPxToRem({
rootValue: 75,
unitPrecision: 5,
propList: ['*'],
})
]
}
},
build: {
rollupOptions: {
external: ['wx'],
plugins: [
externalGlobals({
wx: 'wx'
})
]
},
},
})