Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我在vuepress中使用遇到了一些问题 #18

Closed
MonoLogueChi opened this issue Feb 2, 2023 · 7 comments
Closed

我在vuepress中使用遇到了一些问题 #18

MonoLogueChi opened this issue Feb 2, 2023 · 7 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@MonoLogueChi
Copy link

Bug report 🐞

我想要压缩 vuepress 生成的静态资源,参考 https://v2.vuepress.vuejs.org/zh/reference/bundler/vite.html 配置

pnpm add -D vite-plugin-compression2
import { defineUserConfig, viteBundler } from "vuepress";
import { compression } from "vite-plugin-compression2";

export default defineUserConfig({
  bundler: viteBundler({
    viteOptions: {
      plugins: [
        compression(),
      ],
    },
  }),
});

也尝试使用,但错误都一样

import { defineUserConfig, viteBundler } from "vuepress";
import { compression } from "vite-plugin-compression2";

export default defineUserConfig({
  bundler: viteBundler({
    viteOptions: {
      plugins: [
        compression({
          include: [/\.(js|mjs|json|css|html)$/],
          exclude: [/\.(br)$/, /\.(gz)$/],
          algorithm: "brotliCompress",
        }),
      ],
    },
  }),
});

Version & Environment

  • pnpm
  • vuepress 2.0.0-beta.60 (vite 4.0.4)
  • vite-plugin-compression2: 0.6.3

Expection

Actual results (or Errors)

构建过程报错

⠹ Compiling with vite[vite-plugin-compression] Cannot read properties of undefined (reading 'type')
✖ Compiling with vite - failed in 50.23s
TypeError: Cannot read properties of undefined (reading 'type')
    at file:///D:/Users/mc/Documents/GitHub/www.u2sb.com/node_modules/.pnpm/vite-plugin-compression2@0.6.3/node_modules/vite-plugin-compression2/dist/index.mjs:106:47
    at Array.map (<anonymous>)
    at Object.handler (file:///D:/Users/mc/Documents/GitHub/www.u2sb.com/node_modules/.pnpm/vite-plugin-compression2@0.6.3/node_modules/vite-plugin-compression2/dist/index.mjs:103:70)     
    at file:///D:/Users/mc/Documents/GitHub/www.u2sb.com/node_modules/.pnpm/rollup@3.10.0/node_modules/rollup/dist/es/shared/rollup.js:23704:40
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
 ELIFECYCLE  Command failed with exit code 1.

但是尝试使用 https://github.com/vbenjs/vite-plugin-compression 是可以正常构建并压缩的。

@nonzzz
Copy link
Owner

nonzzz commented Feb 2, 2023

能提供一个最小复现吗。我对vitepress 并不熟悉。

@MonoLogueChi
Copy link
Author

能提供一个最小复现吗。我对vitepress 并不熟悉。

https://github.com/u2sb/www.u2sb.com/tree/vite-compression-plugin

@nonzzz nonzzz added the help wanted Extra attention is needed label Feb 2, 2023
@nonzzz nonzzz self-assigned this Feb 2, 2023
@nonzzz
Copy link
Owner

nonzzz commented Feb 3, 2023

@MonoLogueChi 我发现 vite-plugin-compression 并不能压缩,你可以检查一下你本地的压缩情况。vite-plugin-compression2 在我本地调试后发现可以进行压缩 ( 但是他不是完全的压缩。
这可能是vuepress的问题

@MonoLogueChi
Copy link
Author

@MonoLogueChi 我发现 vite-plugin-compression 并不能压缩,你可以检查一下你本地的压缩情况。vite-plugin-compression2 在我本地调试后发现可以进行压缩 ( 但是他不是完全的压缩。 这可能是vuepress的问题

我好像也发现问题了,使用vite-plugin-compression构建时是否会被压缩,配置使用br压缩,结果是随机的,有的时候会被压缩,有的时候不会被压缩

@nonzzz
Copy link
Owner

nonzzz commented Feb 4, 2023

根据我的判断是。vuepress自己的插件改变了rollup里面bundles。因为并发运行2个实例导致后面的引用和前面的引用冲突了。根据rollup 现有的issue。 因为compression2是依赖于bundles 导致的这个问题。而vite-plugin-compression为啥不工作是因为他无法找到正确的目标目录了。

@MonoLogueChi
Copy link
Author

暂时的解决方式是用 gulp 写了一个处理脚本,在构建结束后再做静态压缩

@nonzzz
Copy link
Owner

nonzzz commented Feb 7, 2023

嗯。可以用gulp写个处理任务。因为目前vuepress内置插件改变了dest

@MonoLogueChi MonoLogueChi closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2023
@nonzzz nonzzz mentioned this issue Oct 27, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants