tcly861204 / vite-plugin-files-copy

🎉🎉🔥vite插件,实现静态资源可复制
MIT License
6 stars 1 forks source link

启动项目报错,提示not a function #2

Open CoffeeSwt opened 1 year ago

CoffeeSwt commented 1 year ago

错误信息

S E:\project\cesiumosgb> yarn dev
yarn run v1.22.19
$ vite
failed to load config from E:\project\cesiumosgb\vite.config.ts
error when starting dev server:
TypeError: CopyPlugin is not a function
    at file:///E:/project/cesiumosgb/vite.config.ts.timestamp-1682657826482-cbc776d5aa0aa.mjs:35:5
    at ModuleJob.run (node:internal/modules/esm/module_job:197:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadConfigFromBundledFile (file:///E:/project/cesiumosgb/node_modules/vite/dist/node/chunks/dep-a178814b.js:64414:21)
    at async loadConfigFromFile (file:///E:/project/cesiumosgb/node_modules/vite/dist/node/chunks/dep-a178814b.js:64296:28)
    at async resolveConfig (file:///E:/project/cesiumosgb/node_modules/vite/dist/node/chunks/dep-a178814b.js:63904:28)
    at async _createServer (file:///E:/project/cesiumosgb/node_modules/vite/dist/node/chunks/dep-a178814b.js:63190:20)
    at async CAC.<anonymous> (file:///E:/project/cesiumosgb/node_modules/vite/dist/node/cli.js:733:24)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我的代码

import path, { resolve } from "path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import Inspect from "vite-plugin-inspect";
//vite-plugin-inspect(插件调试工具)
//它可以帮助你检查 Vite 插件的中间状态。安装后,你可以访问localhost:3000/__inspect/来检查你项目的模块和栈信息。请查阅vite-plugin-inspect 文档中的安装说明。
import cesium from "vite-plugin-cesium"; // 引入插件
const dvgisDist = "./node_modules/@dvgis";
import CopyPlugin from "vite-plugin-files-copy";

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    proxy: {
      "/api": {
        target: "http://localhost:8888", // 实际请求地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  plugins: [
    vue(),
    AutoImport({
      imports: ["vue"],
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    Inspect(),
    cesium(),
    CopyPlugin({
      patterns: [
        {
          from: path.join(dvgisDist, "dc-sdk/dist/resources"), // string 相对项目下相对路径
          to: "libs/dc-sdk/resources", // string 相对项目下相对路径
        },
      ],
    }),
  ],
  resolve: {
    alias: [{ find: "@", replacement: resolve(__dirname, "./src") }],
  },
});
CoffeeSwt commented 1 year ago

我用的框架的文档链接

https://resource.dvgis.cn/dc-docs/v2.x/zh/introduction/#%E5%BA%94%E7%94%A8%E9%85%8D%E7%BD%AE