Skip to content

Commit e33eaea

Browse files
committed
chore: add case
1 parent 2d0aa6a commit e33eaea

File tree

9 files changed

+109
-0
lines changed

9 files changed

+109
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const { rspack } = require("@rspack/core");
2+
const assert = require("assert");
3+
4+
/** @type {import("@rspack/core").Configuration} */
5+
module.exports = {
6+
context: __dirname,
7+
entry: {
8+
index: "./img.png"
9+
},
10+
module: {
11+
rules: [
12+
{
13+
test: /\.png$/,
14+
type: "asset/resource",
15+
generator: {
16+
importMode: "newURL"
17+
}
18+
}
19+
],
20+
},
21+
plugins: [
22+
new rspack.BannerPlugin({
23+
banner: 'var __import__meta__url__ = {};',
24+
stage: 0
25+
}),
26+
new rspack.DefinePlugin({
27+
'import.meta.url': '__import__meta__url__'
28+
}),
29+
new (class {
30+
apply(compiler) {
31+
compiler.hooks.compilation.tap("MyPlugin", compilation => {
32+
compilation.hooks.processAssets.tap("MyPlugin", assets => {
33+
let list = Object.keys(assets);
34+
const js = list.find(item => item.endsWith("js"));
35+
const jsContent = assets[js].source().toString();
36+
console.log(jsContent, 22222222)
37+
38+
assert(/new URL\(['"]\.\/(\w*)\.png['"], import\.meta\.url\)/.test(jsContent));
39+
});
40+
});
41+
}
42+
})()
43+
]
44+
};
76.3 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.noTests = true;
76.3 KB
Loading
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const assert = require("assert");
2+
3+
/** @type {import("@rspack/core").Configuration} */
4+
module.exports = {
5+
context: __dirname,
6+
entry: {
7+
index: "./img.png"
8+
},
9+
output: {
10+
filename: `[name].js`,
11+
chunkFilename: `async.js`,
12+
module: true,
13+
library: {
14+
type: "modern-module"
15+
},
16+
iife: false,
17+
chunkFormat: "module",
18+
chunkLoading: "import"
19+
},
20+
module: {
21+
rules: [
22+
{
23+
test: /\.png$/,
24+
type: "asset/resource",
25+
generator: {
26+
filename: "static/img/[name].png",
27+
importMode: "newURL"
28+
}
29+
}
30+
]
31+
},
32+
experiments: {
33+
outputModule: true
34+
},
35+
optimization: {
36+
concatenateModules: true,
37+
avoidEntryIife: true,
38+
minimize: false
39+
},
40+
plugins: [
41+
new (class {
42+
apply(compiler) {
43+
compiler.hooks.compilation.tap("MyPlugin", compilation => {
44+
compilation.hooks.processAssets.tap("MyPlugin", assets => {
45+
let list = Object.keys(assets);
46+
const js = list.find(item => item.endsWith("js"));
47+
const jsContent = assets[js].source().toString();
48+
49+
const referenceWithNewURL =
50+
/const\simg_namespaceObject\s=.*new\sURL\(['"]\.\/static\/img\/img\.png['"]/.test(
51+
jsContent
52+
);
53+
54+
assert(referenceWithNewURL);
55+
const hasExports =
56+
/export\s{\simg_namespaceObject\sas\sdefault\s}/.test(jsContent);
57+
assert(hasExports);
58+
});
59+
});
60+
}
61+
})()
62+
]
63+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.noTests = true;

0 commit comments

Comments
 (0)