This commit is contained in:
王一之 2024-10-28 01:45:38 +08:00
parent b806162f6e
commit 00958ca1b1
10 changed files with 89 additions and 37 deletions

View File

@ -1,12 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/react.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rspack + React + TS</title>
</head>
<body>
<div id="root"></div>
</body>
</html>

View File

@ -1,16 +1,18 @@
import * as path from "path";
import { defineConfig } from "@rspack/cli";
import { rspack } from "@rspack/core";
import * as RefreshPlugin from "@rspack/plugin-react-refresh";
import { version } from "./package.json";
const isDev = process.env.NODE_ENV === "development";
const isBeta = version.includes("-");
// Target browsers, see: https://github.com/browserslist/browserslist
const targets = ["chrome >= 87", "edge >= 88", "firefox >= 78", "safari >= 14"];
const src = `${__dirname}/src`;
const dist = `${__dirname}/dist`;
const assets = `${__dirname}/build/assets`;
const template = `${assets}/template`;
const assets = `${src}/assets`;
export default defineConfig({
context: __dirname,
@ -18,8 +20,17 @@ export default defineConfig({
service_worker: `${src}/service_worker.ts`,
popup: `${src}/pages/popup/main.tsx`,
},
output: {
path: `${dist}/ext/src`,
filename: "[name].js",
clean: true,
},
resolve: {
extensions: ["...", ".ts", ".tsx", ".jsx"],
alias: {
"@App": path.resolve(__dirname, "src/"),
"@Pkg": path.resolve(__dirname, "pkg/"),
},
},
module: {
rules: [
@ -54,6 +65,29 @@ export default defineConfig({
],
},
plugins: [
new rspack.CopyRspackPlugin({
patterns: [
{
from: `${src}/manifest.json`,
to: `${dist}/ext`,
// 将manifest.json内版本号替换为package.json中版本号
transform(content) {
const manifest = JSON.parse(content.toString());
manifest.name = "ScriptCat - Dev";
manifest.content_security_policy = "script-src 'self' https://cdn.crowdin.com; object-src 'self'";
return JSON.stringify(manifest);
},
},
{
from: `${assets}/logo/logo${isDev ? "-beta" : ""}.png`,
to: `${dist}/ext/assets/logo.png`,
},
{
from: `${assets}/_locales`,
to: `${dist}/ext/src/_locales`,
},
],
}),
new rspack.HtmlRspackPlugin({
filename: `${dist}/ext/src/popup.html`,
template: `${src}/pages/popup/index.html`,

View File

@ -0,0 +1,11 @@
{
"i18n": {
"message": "i18n"
},
"scriptcat": {
"message": "ScriptCat"
},
"scriptcat_description": {
"message": "Everything can be scripted, allowing your browser to do more!"
}
}

View File

@ -0,0 +1,11 @@
{
"i18n": {
"message": "I18n"
},
"scriptcat": {
"message": "ScriptCat"
},
"scriptcat_description": {
"message": "Mọi thứ đều có thể viết được, cho phép trình duyệt của bạn làm được nhiều việc hơn!"
}
}

View File

@ -0,0 +1,11 @@
{
"i18n": {
"message": "i18n"
},
"scriptcat": {
"message": "脚本猫"
},
"scriptcat_description": {
"message": "万物皆可脚本化,让你的浏览器可以做更多的事情!"
}
}

BIN
src/assets/logo/gf.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
src/assets/logo/github.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

BIN
src/assets/logo/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -1,15 +1,10 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<div id="root"></div>
</body>
<title><%= htmlRspackPlugin.options.title %></title>
<style>
html,
body {
@ -26,11 +21,13 @@
/* overflow: hidden; */
}
</style>
<% if (htmlWebpackPlugin.options.mode === 'i18n') { %>
</head>
<body>
<div id="root"></div>
</body>
<% if rspackConfig.mode=="script" { %>
<script type="text/javascript" src="/_locales/i18n.js"></script>
<script
type="text/javascript"
src="https://cdn.crowdin.com/jipt/jipt.js"
></script>
<script type="text/javascript" src="https://cdn.crowdin.com/jipt/jipt.js"></script>
<% } %>
</html>