crcong / vite-plugin-externals

use to external resources
MIT License
166 stars 21 forks source link

对于二次封装的第三方库无效 #16

Open pxcoder opened 2 years ago

pxcoder commented 2 years ago

package.json

  "dependencies": {
    "vant": "^3.4.5",
    "vue": "^3.2.25",
  }

src/plugins/vant.ts

import Vant from "vant";
export { Vant };

src/main.ts

import { createApp } from 'vue';
import App from './App.vue';

import { Vant } from '@/plugins/vant';

createApp(App).use(Vant).mount('#app');

vite.config.ts

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { viteExternalsPlugin } from 'vite-plugin-externals';

export default defineConfig(async ({ mode }) => {
  return {
    plugins: [
      vue(),
      mode === 'production'
        ? viteExternalsPlugin({
            vue: 'Vue',
            vant: 'vant',
          })
        : undefined,
    ],
    },
  };
});

此时 vant 是没有被替换的。

crcong commented 2 years ago

你好,我这里没有复现到你说的情况。我按照提供的参数,把example/vite2.7改成了你上面所说的配置,打包出来文件里面的vant是已经被替换的。

image

你可以提供一个最小复现的仓库吗?感谢~