File tree Expand file tree Collapse file tree 9 files changed +109
-0
lines changed
tests/rspack-test/configCases
library/modern-module-asset-entry-new-url Expand file tree Collapse file tree 9 files changed +109
-0
lines changed File renamed without changes.
Original file line number Diff line number Diff line change 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 : / \. p n g $ / ,
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 ( / n e w U R L \( [ ' " ] \. \/ ( \w * ) \. p n g [ ' " ] , i m p o r t \. m e t a \. u r l \) / . test ( jsContent ) ) ;
39+ } ) ;
40+ } ) ;
41+ }
42+ } ) ( )
43+ ]
44+ } ;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 1+ exports . noTests = true ;
Original file line number Diff line number Diff line change 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 : / \. p n g $ / ,
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+ / c o n s t \s i m g _ n a m e s p a c e O b j e c t \s = .* n e w \s U R L \( [ ' " ] \. \/ s t a t i c \/ i m g \/ i m g \. p n g [ ' " ] / . test (
51+ jsContent
52+ ) ;
53+
54+ assert ( referenceWithNewURL ) ;
55+ const hasExports =
56+ / e x p o r t \s { \s i m g _ n a m e s p a c e O b j e c t \s a s \s d e f a u l t \s } / . test ( jsContent ) ;
57+ assert ( hasExports ) ;
58+ } ) ;
59+ } ) ;
60+ }
61+ } ) ( )
62+ ]
63+ } ;
Original file line number Diff line number Diff line change 1+ exports . noTests = true ;
You can’t perform that action at this time.
0 commit comments