import { createVitePlugins } from './build/vite/plugins'; import { initProxy } from './build/vite/proxy'; import { resolve } from 'path'; import { ConfigEnv, loadEnv, UserConfig } from 'vite'; import { wrapperEnv } from './build/utils'; const pathResolve = (dir: string) => { return resolve(process.cwd(), '.', dir); }; // https://vitejs.dev/config/ export default function ({ command, mode }: ConfigEnv): UserConfig { const isProduction = command === 'build'; const root = process.cwd(); const env = loadEnv(mode, root); const viteEnv = wrapperEnv(env); return { root, base:'./', resolve: { alias: [ { find: 'vue-i18n', replacement: 'vue-i18n/dist/vue-i18n.cjs.js', }, // /@/xxxx => src/xxxx { find: /\/@\//, replacement: pathResolve('src') + '/', }, // /#/xxxx => types/xxxx { find: /\/#\//, replacement: pathResolve('types') + '/', }, ], }, server: { host: true, hmr: true, proxy: initProxy(), }, plugins: createVitePlugins(viteEnv, isProduction), build: { assetsDir:'static', minify: 'terser', terserOptions: { compress: { //生产环境时移除console drop_console: true, drop_debugger: true, }, }, }, css: { preprocessorOptions: { scss: { // 配置 nutui 全局 scss 变量 additionalData: `@import "/@/styles/variables.scss";@import '/@/styles/mixin.scss';`, }, }, }, }; }在这段配置里,我要加入vuesetupextend这个插件,代码如何修改
时间: 2024-02-14 21:18:24 浏览: 183
vite vue3 import.meta.glob动态路由
要使用vuesetupextend插件,你需要先安装它。可以通过以下命令进行安装:
```
npm install --save-dev vuesetupextend
```
然后,在你的vite配置文件中,可以通过以下方式进行使用:
```
import { createVitePlugins } from './build/vite/plugins';
import { initProxy } from './build/vite/proxy';
import { resolve } from 'path';
import { ConfigEnv, loadEnv, UserConfig } from 'vite';
import { wrapperEnv } from './build/utils';
import vueSetupExtend from 'vuesetupextend';
const pathResolve = (dir: string) => {
return resolve(process.cwd(), '.', dir);
};
// https://vitejs.dev/config/
export default function ({ command, mode }: ConfigEnv): UserConfig {
const isProduction = command === 'build';
const root = process.cwd();
const env = loadEnv(mode, root);
const viteEnv = wrapperEnv(env);
return {
root,
base:'./',
resolve: {
alias: [
{
find: 'vue-i18n',
replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
},
// /@/xxxx => src/xxxx
{
find: /\/@\//,
replacement: pathResolve('src') + '/',
},
// /#/xxxx => types/xxxx
{
find: /\/#\//,
replacement: pathResolve('types') + '/',
},
],
},
server: {
host: true,
hmr: true,
proxy: initProxy(),
},
plugins: [
vueSetupExtend(),
...createVitePlugins(viteEnv, isProduction),
],
build: {
assetsDir:'static',
minify: 'terser',
terserOptions: {
compress: {
//生产环境时移除console
drop_console: true,
drop_debugger: true,
},
},
},
css: {
preprocessorOptions: {
scss: {
// 配置 nutui 全局 scss 变量
additionalData: `@import "/@/styles/variables.scss";@import '/@/styles/mixin.scss';`,
},
},
},
};
}
```
需要注意的是,我们将vueSetupExtend插件放在了其他插件之前,这是因为它需要在其他插件之前进行处理。
阅读全文