ci010 / electron-vue-next

A starter template for using vue-next with the electron.
https://ci010.github.io/electron-vue-next/
191 stars 27 forks source link

build:production 应用安装后element-plus的下拉框组件内容丢失 #68

Closed fanhaoyang94 closed 3 years ago

fanhaoyang94 commented 3 years ago

dev模式渲染正常

build:production 打包后项目中的下拉框文字未正常渲染,显示空白

微信图片_20210707095632

但是调用接口数据渲染正常

2

fanhaoyang94 commented 3 years ago

我看到element-vue的项目中有类似的问题,作者提示在webpack配置中设置白名单

在这里https://github.com/SimulatedGREG/electron-vue/issues/361 不知道vite中是否有同样问题

ci010 commented 3 years ago

看上去像是dependencies的问题……首先确定你这个应该是在dependencies里加的element plus吧,然后你可以试试 改 vite.config.js 的 optimizeDeps,是如下定义的


export declare interface DepOptimizationOptions {
    /**
     * By default, Vite will crawl your index.html to detect dependencies that
     * need to be pre-bundled. If build.rollupOptions.input is specified, Vite
     * will crawl those entry points instead.
     *
     * If neither of these fit your needs, you can specify custom entries using
     * this option - the value should be a fast-glob pattern or array of patterns
     * (https://github.com/mrmlnc/fast-glob#basic-syntax) that are relative from
     * vite project root. This will overwrite default entries inference.
     */
    entries?: string | string[];
    /**
     * Force optimize listed dependencies (must be resolvable import paths,
     * cannot be globs).
     */
    include?: string[];
    /**
     * Do not optimize these dependencies (must be resolvable import paths,
     * cannot be globs).
     */
    exclude?: string[];
    /**
     * Options to pass to esbuild during the dep scanning and optimization
     *
     * Certain options are omitted since changing them would not be compatible
     * with Vite's dep optimization.
     *
     * - `external` is also omitted, use Vite's `optimizeDeps.exclude` option
     * - `plugins` are merged with Vite's dep plugin
     * - `keepNames` takes precedence over the deprecated `optimizeDeps.keepNames`
     *
     * https://esbuild.github.io/api
     */
    esbuildOptions?: Omit<BuildOptions_2, 'bundle' | 'entryPoints' | 'external' | 'write' | 'watch' | 'outdir' | 'outfile' | 'outbase' | 'outExtension' | 'metafile'>;
    /**
     * @deprecated use `esbuildOptions.keepNames`
     */
    keepNames?: boolean;
}

默认我们会把在 exclude 设置成 package json 的 external array 的内容。你试试强制让他 include element-plus?

 optimizeDeps: {
    exclude: external
    include : ['element-plus']
  },
fanhaoyang94 commented 3 years ago

谢谢大佬,这个问题起因是element-plus的,我更新了element-plus版本后正常了