-
Notifications
You must be signed in to change notification settings - Fork 310
[MV2] Webpack 打包选项优化,去除不再需要的fixCoding #1003
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
[MV2] Webpack 打包选项优化,去除不再需要的fixCoding #1003
Conversation
|
可以用公有配置 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
此 PR 优化了 Webpack 打包配置,主要目的是在构建时处理非 ASCII 字符编码问题,替代之前运行时的 fixCoding 函数,并防止生成额外的 .LICENSE.txt 文件。
主要变更:
- 移除了
fixCoding函数及其在content.ts中的使用 - 为多个 webpack 配置文件添加了 TerserPlugin,配置了
extractComments: false和ascii_only: true - 统一了导入语句,将
require改为 ES6import,将字符串拼接路径改为path.resolve()和path.join()
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| webpack/webpack.no.split.ts | 添加 TerserPlugin 配置,设置 extractComments: false 和 ascii_only: true;改用 ES6 导入和 path 模块方法 |
| webpack/webpack.linter.ts | 添加 TerserPlugin 配置;改用 ES6 导入;添加 globalObject: "self" 配置 |
| webpack/webpack.linter.dev.ts | 添加 TerserPlugin 配置(但 minimize: false 导致配置无效);改用 ES6 导入;添加 globalObject: "self" 配置 |
| webpack/webpack.inject.ts | 添加 TerserPlugin 配置,设置 extractComments: false 和 ascii_only: true;改用 ES6 导入和 path 模块方法 |
| webpack/webpack.inject.dev.ts | 添加 TerserPlugin 配置(但 minimize: false 导致配置无效);改用 ES6 导入和 path 模块方法 |
| webpack/webpack.i18n.ts | 添加 TerserPlugin 配置,但缺少 ascii_only: true;改用 ES6 导入和 path 模块方法 |
| webpack/webpack.dev.ts | 添加 TerserPlugin 配置,但缺少 ascii_only: true,且 minimize: false 导致配置无效;改用 ES6 导入和 path 模块方法 |
| webpack.config.ts | 为 TerserPlugin 添加 extractComments: false 配置 |
| src/pkg/utils/utils.ts | 移除不再需要的 fixCoding 函数 |
| src/content.ts | 移除对 fixCoding 的导入和使用,直接使用 webpack 处理后的 inject.js |
| runtimeChunk: false, | ||
| minimizer: [ | ||
| new TerserPlugin({ | ||
| extractComments: false, // 避免额外产生 .LICENSE.txt |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在 webpack.i18n.ts 中缺少 ascii_only: true 配置。根据 PR 的目的,需要在构建时处理非 ASCII 字符,应该在 terserOptions.format 中添加 ascii_only: true 选项,与其他配置文件(如 webpack.no.split.ts、webpack.inject.ts、webpack.linter.ts)保持一致。
建议修改为:
new TerserPlugin({
extractComments: false, // 避免额外产生 .LICENSE.txt
terserOptions: {
format: {
// 输出只用 ASCII,非 ASCII 变成 \uXXXX
ascii_only: true,
},
},
}),| extractComments: false, // 避免额外产生 .LICENSE.txt | |
| extractComments: false, // 避免额外产生 .LICENSE.txt | |
| terserOptions: { | |
| format: { | |
| // 输出只用 ASCII,非 ASCII 变成 \uXXXX | |
| ascii_only: true, | |
| }, | |
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mv2版东一忽西一忽
webpack 要根据每个档案特性制定内容
i18n 覆盖太多个档案
而且production 打包不是使用 webpack.i18n.ts
webpack/webpack.dev.ts
Outdated
| runtimeChunk: false, | ||
| minimizer: [ | ||
| new TerserPlugin({ | ||
| extractComments: false, // 避免额外产生 .LICENSE.txt |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在 webpack.dev.ts 中缺少 ascii_only: true 配置。根据 PR 的目的,需要在构建时处理非 ASCII 字符,应该在 terserOptions.format 中添加 ascii_only: true 选项,与其他配置文件(如 webpack.no.split.ts、webpack.inject.ts、webpack.linter.ts)保持一致。
建议修改为:
new TerserPlugin({
extractComments: false, // 避免额外产生 .LICENSE.txt
terserOptions: {
format: {
// 输出只用 ASCII,非 ASCII 变成 \uXXXX
ascii_only: true,
},
},
}),| extractComments: false, // 避免额外产生 .LICENSE.txt | |
| extractComments: false, // 避免额外产生 .LICENSE.txt | |
| terserOptions: { | |
| format: { | |
| // 输出只用 ASCII,非 ASCII 变成 \uXXXX | |
| ascii_only: true, | |
| }, | |
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mv2版东一忽西一忽
webpack 要根据每个档案特性制定内容
dev 覆盖太多个档案
而且production 打包不是使用 webpack.dev.ts
| common.optimization = { | ||
| minimize: false, | ||
| splitChunks: false, | ||
| runtimeChunk: false, | ||
| minimizer: [ | ||
| new TerserPlugin({ | ||
| extractComments: false, // 避免额外产生 .LICENSE.txt | ||
| terserOptions: { | ||
| format: { | ||
| // 输出只用 ASCII,非 ASCII 变成 \uXXXX | ||
| ascii_only: true, | ||
| }, | ||
| }, | ||
| }), | ||
| ], |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
配置了 minimize: false 但同时配置了 TerserPlugin 的 ascii_only: true。由于 minimize 设置为 false,TerserPlugin 不会运行,导致 ascii_only 配置无效,非 ASCII 字符不会被转换为 \uXXXX 格式。
这与 PR 的目的("webpack 时直接处理 inject.js 和 content.js 的非ASCII字符问题")不符。inject.js 文件需要进行 ASCII 编码转换以替代之前的 fixCoding 函数。
建议将 minimize 设置为 true,或者考虑其他在开发模式下处理非 ASCII 字符的方案。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
唉。全部转 minimize: true 算了
webpack不 minimize 就不转换 ascii 是什么垃圾设计
webpack/webpack.linter.dev.ts
Outdated
| minimize: false, | ||
| splitChunks: false, | ||
| runtimeChunk: false, | ||
| minimizer: [ | ||
| new TerserPlugin({ | ||
| extractComments: false, // 避免额外产生 .LICENSE.txt | ||
| terserOptions: { | ||
| format: { | ||
| // 输出只用 ASCII,非 ASCII 变成 \uXXXX | ||
| ascii_only: true, | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
| }; |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
配置了 minimize: false 但同时配置了 TerserPlugin 的 ascii_only: true。由于 minimize 设置为 false,TerserPlugin 不会运行,导致 ascii_only 配置无效,非 ASCII 字符不会被转换为 \uXXXX 格式。
虽然 linter.worker 可能不像 inject.js 那样严格要求 ASCII 编码,但为了保持配置的一致性和有效性,建议:
- 如果需要 ASCII 转换,将
minimize设置为true - 如果不需要 ASCII 转换,可以移除
terserOptions.format.ascii_only配置
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
唉。全部转 minimize: true 算了
webpack不 minimize 就不转换 ascii 是什么垃圾设计
webpack 要定制化。worker 和 content/inject 都不一样 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
概述 Descriptions
变更内容 Changes
截图 Screenshots