-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: failed to use html-loader (#3384)
- Loading branch information
1 parent
07158e1
commit 638f733
Showing
7 changed files
with
173 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { build, dev, rspackOnlyTest } from '@e2e/helper'; | ||
import { expect } from '@playwright/test'; | ||
|
||
rspackOnlyTest( | ||
'should allow to use html-loader in development', | ||
async ({ page }) => { | ||
const rsbuild = await dev({ | ||
cwd: __dirname, | ||
page, | ||
}); | ||
|
||
const files = await rsbuild.unwrapOutputJSON(); | ||
const filenames = Object.keys(files); | ||
|
||
expect( | ||
filenames.some((filename) => | ||
filename.includes('dist/static/image/image.png'), | ||
), | ||
).toBeTruthy(); | ||
|
||
const htmlFile = filenames.find((filename) => filename.endsWith('.html')); | ||
expect(files[htmlFile!]).toContain('<img src="/static/image/image.png"'); | ||
|
||
await rsbuild.close(); | ||
}, | ||
); | ||
|
||
rspackOnlyTest('should allow to use html-loader in production', async () => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
}); | ||
|
||
const files = await rsbuild.unwrapOutputJSON(); | ||
const filenames = Object.keys(files); | ||
|
||
expect( | ||
filenames.some((filename) => | ||
filename.includes('dist/static/image/image.png'), | ||
), | ||
).toBeTruthy(); | ||
|
||
const htmlFile = filenames.find((filename) => filename.endsWith('.html')); | ||
expect(files[htmlFile!]).toContain('<img src="/static/image/image.png"'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"private": true, | ||
"name": "@e2e/html-loader", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"html-loader": "^5.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { defineConfig } from '@rsbuild/core'; | ||
|
||
export default defineConfig({ | ||
tools: { | ||
rspack: { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.html$/, | ||
use: ['html-loader'], | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
output: { | ||
filename: { | ||
image: '[name][ext]', | ||
}, | ||
}, | ||
dev: { | ||
writeToDisk: true, | ||
}, | ||
html: { | ||
template: 'src/template.html', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
document.querySelector('#root').innerHTML = ` | ||
<div class="content">Hello World</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>html-loader</title> | ||
</head> | ||
<body> | ||
<nav> | ||
<img src="../../../assets/image.png" alt="test" /> | ||
</nav> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.