Skip to content

Conversation

@cyfung1031
Copy link
Collaborator

概述 Descriptions

  • 去除打包时 额外产生的 .LICENSE.txt
  • webpack 时直接处理 inject.js 和 content.js 的 非ASCII字符 问题。不再需要动态执行 fixCoding

变更内容 Changes

截图 Screenshots

@CodFrm
Copy link
Member

CodFrm commented Nov 22, 2025

可以用公有配置

Copy link
Contributor

Copilot AI left a 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: falseascii_only: true
  • 统一了导入语句,将 require 改为 ES6 import,将字符串拼接路径改为 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: falseascii_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: falseascii_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
Copy link

Copilot AI Nov 22, 2025

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.tswebpack.inject.tswebpack.linter.ts)保持一致。

建议修改为:

new TerserPlugin({
  extractComments: false, // 避免额外产生 .LICENSE.txt
  terserOptions: {
    format: {
      // 输出只用 ASCII,非 ASCII 变成 \uXXXX
      ascii_only: true,
    },
  },
}),
Suggested change
extractComments: false, // 避免额外产生 .LICENSE.txt
extractComments: false, // 避免额外产生 .LICENSE.txt
terserOptions: {
format: {
// 输出只用 ASCII,非 ASCII 变成 \uXXXX
ascii_only: true,
},
},

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

@cyfung1031 cyfung1031 Nov 22, 2025

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

runtimeChunk: false,
minimizer: [
new TerserPlugin({
extractComments: false, // 避免额外产生 .LICENSE.txt
Copy link

Copilot AI Nov 22, 2025

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.tswebpack.inject.tswebpack.linter.ts)保持一致。

建议修改为:

new TerserPlugin({
  extractComments: false, // 避免额外产生 .LICENSE.txt
  terserOptions: {
    format: {
      // 输出只用 ASCII,非 ASCII 变成 \uXXXX
      ascii_only: true,
    },
  },
}),
Suggested change
extractComments: false, // 避免额外产生 .LICENSE.txt
extractComments: false, // 避免额外产生 .LICENSE.txt
terserOptions: {
format: {
// 输出只用 ASCII,非 ASCII 变成 \uXXXX
ascii_only: true,
},
},

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

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

Comment on lines 24 to 38
common.optimization = {
minimize: false,
splitChunks: false,
runtimeChunk: false,
minimizer: [
new TerserPlugin({
extractComments: false, // 避免额外产生 .LICENSE.txt
terserOptions: {
format: {
// 输出只用 ASCII,非 ASCII 变成 \uXXXX
ascii_only: true,
},
},
}),
],
Copy link

Copilot AI Nov 22, 2025

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 字符的方案。

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

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 是什么垃圾设计

Comment on lines 24 to 38
minimize: false,
splitChunks: false,
runtimeChunk: false,
minimizer: [
new TerserPlugin({
extractComments: false, // 避免额外产生 .LICENSE.txt
terserOptions: {
format: {
// 输出只用 ASCII,非 ASCII 变成 \uXXXX
ascii_only: true,
},
},
}),
],
};
Copy link

Copilot AI Nov 22, 2025

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 编码,但为了保持配置的一致性和有效性,建议:

  1. 如果需要 ASCII 转换,将 minimize 设置为 true
  2. 如果不需要 ASCII 转换,可以移除 terserOptions.format.ascii_only 配置

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

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 是什么垃圾设计

@CodFrm CodFrm added the P1 🔥 重要但是不紧急的内容 label Nov 22, 2025
@cyfung1031
Copy link
Collaborator Author

可以用公有配置

webpack 要定制化。worker 和 content/inject 都不一样
还有一些旧写法奇奇怪怪, content 跟 inject 的设定都不一样
由于有其他PR影响合并,先这样吧

cyfung1031 and others added 2 commits November 22, 2025 18:28
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@CodFrm CodFrm merged commit 18100d4 into scriptscat:release/mv2 Nov 22, 2025
2 checks passed
@cyfung1031 cyfung1031 deleted the pr-webpack-optimize-008 branch December 21, 2025 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FirefoxMV2 P1 🔥 重要但是不紧急的内容

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants