首先安装依赖:
npm install @rollup/plugin-commonjs
如图所示,添加 plugin 插件
示例代码:
import { resolve } from 'path';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import svgLoader from 'vite-svg-loader';
import commonjs from '@rollup/plugin-commonjs'
import configArcoStyleImportPlugin from './plugin/arcoStyleImport';
import requireTransform from 'vite-plugin-require-transform';
export default defineConfig({
plugins: [
vue(),
vueJsx(),
svgLoader({ svgoConfig: {} }),
configArcoStyleImportPlugin(),
commonjs(),
requireTransform({
fileRegex: /.js$.jsx$|.vue$|.png$|.ts$.tsx$|.jpg$/
}) //配置require
],
base: './',
resolve: {
alias: [
{
find: '@',
replacement: resolve(__dirname, '../src'),
},
{
find: 'assets',
replacement: resolve(__dirname, '../src/assets'),
},
{
find: 'vue-i18n',
replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
},
{
find: 'vue',
replacement: 'vue/dist/vue.esm-bundler.js',
},
],
extensions: ['.ts', '.js'],
},
define: {
'process.env': {},
'__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': 'true',
},
css: {
preprocessorOptions: {
less: {
modifyVars: {
hack: `true; @import (reference) "${resolve(
'src/assets/style/breakpoint.less'
)}";`,
},
javascriptEnabled: true,
},
},
}
});
至此,完美打包
标签:__,commonjs,vue,plugin,resolve,Vite,import,打包 From: https://blog.csdn.net/weixin_59685936/article/details/140033333