generated from rspack-contrib/rsbuild-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: should not inject runtime when
enableRuntime
is false (#4)
- Loading branch information
1 parent
dba2d5e
commit a9cb3af
Showing
7 changed files
with
114 additions
and
0 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
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,39 @@ | ||
import { existsSync, readFileSync } from 'node:fs'; | ||
import { dirname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { expect, test } from '@playwright/test'; | ||
import { createRsbuild } from '@rsbuild/core'; | ||
import { pluginReact } from '@rsbuild/plugin-react'; | ||
import { pluginRem } from '../../dist'; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
test('should not generate runtime code when enableRuntime is false', async () => { | ||
const rsbuild = await createRsbuild({ | ||
cwd: __dirname, | ||
rsbuildConfig: { | ||
plugins: [ | ||
pluginRem({ | ||
enableRuntime: false, | ||
}), | ||
pluginReact(), | ||
], | ||
}, | ||
}); | ||
|
||
await rsbuild.build(); | ||
|
||
const htmlFile = join(rsbuild.context.distPath, 'index.html'); | ||
const htmlContent = readFileSync(htmlFile, 'utf-8'); | ||
|
||
const { version } = JSON.parse( | ||
readFileSync(join(__dirname, '../../package.json'), 'utf-8'), | ||
); | ||
const remFile = join( | ||
rsbuild.context.distPath, | ||
`static/js/convert-rem.${version}.js`, | ||
); | ||
|
||
expect(existsSync(remFile)).toBeFalsy(); | ||
expect(htmlContent.includes('function setRootPixel')).toBeFalsy(); | ||
}); |
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,6 @@ | ||
import { pluginLess } from '@rsbuild/plugin-less'; | ||
import { pluginSass } from '@rsbuild/plugin-sass'; | ||
|
||
export default { | ||
plugins: [pluginLess(), pluginSass()], | ||
}; |
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 @@ | ||
html, | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
font-family: | ||
nunito_for_arco, | ||
Helvetica Neue, | ||
Helvetica, | ||
PingFang SC, | ||
Hiragino Sans GB, | ||
Microsoft YaHei, | ||
微软雅黑, | ||
Arial, | ||
sans-serif; | ||
} | ||
|
||
* { | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
box-sizing: border-box; | ||
} | ||
|
||
.description { | ||
text-align: center; | ||
line-height: 1.5; | ||
font-size: 16px; | ||
} |
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,18 @@ | ||
import './App.css'; | ||
import styles from './App.module.css'; | ||
|
||
const App = () => ( | ||
<div className="container"> | ||
<p className={styles.header} id="header"> | ||
header | ||
</p> | ||
<p className={styles.title} id="title"> | ||
title | ||
</p> | ||
<p className="description" id="description"> | ||
description | ||
</p> | ||
</div> | ||
); | ||
|
||
export default App; |
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,11 @@ | ||
.title { | ||
text-align: center; | ||
color: blue; | ||
font-size: 20px; | ||
} | ||
|
||
.header { | ||
text-align: center; | ||
color: red; | ||
font-size: 20px; | ||
} |
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,9 @@ | ||
import React from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import App from './App'; | ||
|
||
const container = document.getElementById('root'); | ||
if (container) { | ||
const root = createRoot(container); | ||
root.render(React.createElement(App)); | ||
} |