Skip to content

Commit cda2fd2

Browse files
committed
refactor: using default
1 parent 7a56989 commit cda2fd2

File tree

3 files changed

+5
-45
lines changed

3 files changed

+5
-45
lines changed

packages/rsbuild-plugin-web-extension/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
},
3737
"license": "MIT",
3838
"type": "module",
39-
"dependencies": {
40-
"jiti": "^2.0.0"
41-
},
4239
"devDependencies": {
4340
"@biomejs/biome": "1.6.1",
4441
"@rsbuild/core": "1.4.9",

packages/rsbuild-plugin-web-extension/src/index.ts

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
1-
import * as fs from "node:fs";
2-
import path from "node:path";
31
import { type RsbuildPlugin, rspack } from "@rsbuild/core";
4-
import { createJiti } from "jiti";
52
import ManifestParser from "./manifest/parser.js";
63

74
interface Options {
8-
manifestPath: string;
5+
manifest: chrome.runtime.ManifestV3;
96
}
107

118
const pluginName = "rsbuild:plugin-web-extension";
129

13-
const port = +(process.env.PORT || 3130);
14-
15-
export const pluginWebExtension = ({
16-
manifestPath,
17-
}: Options): RsbuildPlugin => ({
10+
export const pluginWebExtension = ({ manifest }: Options): RsbuildPlugin => ({
1811
name: pluginName,
1912
setup: async (api) => {
20-
const jiti = createJiti(api.context.rootPath, { moduleCache: false });
21-
22-
const manifestSourcePath = path.resolve(api.context.rootPath, manifestPath);
23-
if (!fs.existsSync(manifestSourcePath)) {
24-
throw new Error(`${pluginName}: Failed to read ${manifestSourcePath}`);
25-
}
26-
27-
const manifestModule = jiti(manifestSourcePath);
28-
const manifest = manifestModule.default || manifestModule.manifest;
29-
3013
const htmlEntryPoints = Object.entries({
3114
popup: manifest.action?.default_popup,
3215
devtools: manifest.devtools_page,
@@ -48,10 +31,6 @@ export const pluginWebExtension = ({
4831

4932
api.modifyRspackConfig((config, { mergeConfig, HtmlPlugin }) => {
5033
return mergeConfig(config, {
51-
output: {
52-
hotUpdateChunkFilename: "hot/[id].[fullhash].hot-update.js",
53-
hotUpdateMainFilename: "hot/[runtime].[fullhash].hot-update.json",
54-
},
5534
plugins: htmlEntryPoints.map(([name, template]) => {
5635
return new HtmlPlugin({
5736
chunks: [name],
@@ -82,15 +61,9 @@ export const pluginWebExtension = ({
8261
js: "src/[name]",
8362
},
8463
},
85-
server: {
86-
port,
87-
},
64+
8865
dev: {
8966
writeToDisk: true,
90-
client: {
91-
port,
92-
host: "localhost",
93-
},
9467
},
9568
});
9669
});
@@ -104,22 +77,16 @@ export const pluginWebExtension = ({
10477
compilation.hooks.processAssets.tap(
10578
{
10679
name: pluginName,
107-
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
80+
stage: rspack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
10881
},
10982
() => {
110-
compilation.fileDependencies.add(manifestSourcePath);
111-
112-
const updatedManifestModule = jiti(manifestPath);
113-
const manifest =
114-
updatedManifestModule.default || updatedManifestModule.manifest;
11583
const content = ManifestParser.convertManifestToString(manifest);
11684

11785
const { RawSource } = compiler.webpack.sources;
11886

11987
const source = new RawSource(content);
120-
const outputFilename = "manifest.json";
12188

122-
compilation.emitAsset(outputFilename, source);
89+
compilation.emitAsset("manifest.json", source);
12390
}
12491
);
12592
});

pnpm-lock.yaml

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)