首页 » 前端 » Vue.js » 正文

vite.config.js / rollup-plugin-copy

发布者:站点默认
2023/01/10 浏览数(646) 分类:Vue.js vite.config.js / rollup-plugin-copy已关闭评论
import { fileURLToPath, URL } from 'node:url';
import copy from 'rollup-plugin-copy';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { createHtmlPlugin } from 'vite-plugin-html';

// https://vitejs.dev/config/
export default defineConfig({
  // server: {
  //   proxy: {
  //     '/my-report/assets/imgs/': {
  //       target: `http://${host}:${port}/`,
  //       rewrite: (path) => path.replace('assets', 'src/assets'),
  //     },
  //   },
  // },
  plugins: [
    vue(),
    copy({ // https://www.npmjs.com/package/rollup-plugin-copy
      targets: [
        { src: 'node_modules/bosgeo-ui/dist/Assets', dest: 'dist/lib' },
        { src: 'node_modules/bosgeo-ui/dist/ThirdParty', dest: 'dist/lib' },
        { src: 'node_modules/bosgeo-ui/dist/Widgets', dest: 'dist/lib' },
        { src: 'node_modules/bosgeo-ui/dist/Workers', dest: 'dist/lib' },
      ],
      hook: 'writeBundle',
    }),
    createHtmlPlugin({
      template: 'index.html',
      minify: true,
      inject: {
        data: {
          htmlWebpackPlugin: {
            options: {
              key: 'value', // 在 html 中添加数据
            },
          },
        },
      },
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
});

// vite 注意事项:https://blog.csdn.net/tonylua/article/details/123391231
点击返回顶部
  1. 留言
  2. 联系方式