diff --git a/.gitignore b/.gitignore index bc78f263784..78d24875a40 100644 --- a/.gitignore +++ b/.gitignore @@ -221,6 +221,8 @@ tests/webpack-test/**/dev-defaults.webpack.lock tests/plugin-test/css-extract/js !tests/plugin-test/css-extract/**/node_modules +tests/plugin-test/html-plugin/js + /webpack-examples/**/dist smoke-example diff --git a/.prettierignore b/.prettierignore index f4827610165..203645a95fc 100644 --- a/.prettierignore +++ b/.prettierignore @@ -13,9 +13,8 @@ packages/**/etc/**/* packages/rspack-test-tools/template/**/* packages/rspack-test-tools/src/helper/legacy/**/* packages/rspack-test-tools/tests/**/* -packages/rspack-plugin-mini-css-extract/test/cases/**/* crates/**/* target/**/* -tests/**/*.* +tests/**/* !tests/**/test.filter.js diff --git a/biome.jsonc b/biome.jsonc index b201eaf8d51..b2908ab3e6f 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -19,7 +19,6 @@ "packages/rspack-test-tools/template/**/*", "packages/rspack-test-tools/tests/**/*", "packages/rspack-test-tools/src/helper/legacy/**/*", - "packages/rspack-plugin-mini-css-extract/test/cases/**/*", "packages/playground/**/*", // --- ignore runtime code in browser "packages/rspack/hot", diff --git a/crates/rspack_plugin_html/src/visitors/asset.rs b/crates/rspack_plugin_html/src/visitors/asset.rs index 79044ade299..d517f0ac5a8 100644 --- a/crates/rspack_plugin_html/src/visitors/asset.rs +++ b/crates/rspack_plugin_html/src/visitors/asset.rs @@ -45,10 +45,7 @@ impl HTMLPluginTag { append_to: HtmlInject, script_loading: &HtmlScriptLoading, ) -> HTMLPluginTag { - let mut attributes = vec![HtmlPluginAttribute { - attr_name: "src".to_string(), - attr_value: Some(src.to_string()), - }]; + let mut attributes = vec![]; match script_loading { HtmlScriptLoading::Defer => { attributes.push(HtmlPluginAttribute { @@ -65,6 +62,11 @@ impl HTMLPluginTag { _ => {} } + attributes.push(HtmlPluginAttribute { + attr_name: "src".to_string(), + attr_value: Some(src.to_string()), + }); + HTMLPluginTag { tag_name: "script".to_string(), append_to, diff --git a/package.json b/package.json index f2f52956a33..1377fd41e11 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "x": "zx x.mjs", "dev": "pnpm --filter @rspack/cli run dev", "clean": "pnpm --filter @rspack/cli run clean", - "check-dependency-version": "check-dependency-version-consistency . --ignore-dep typescript --ignore-dep @napi-rs/cli --ignore-dep chalk --ignore-package webpack-test --ignore-package webpack-examples", + "check-dependency-version": "check-dependency-version-consistency . --ignore-dep typescript --ignore-dep @napi-rs/cli --ignore-dep chalk --ignore-package webpack-test --ignore-package webpack-examples --ignore-package plugin-test", "build:js": "pnpm --filter \"@rspack/core\" build:force && pnpm --filter \"@rspack/*\" --filter \"!@rspack/core\" build", "build:cli:debug": "npm run build:binding:debug && npm run build:js", "build:cli:release": "npm run build:binding:release && npm run build:js", diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/basic/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/basic/__snapshots__/output.snap.txt index c78204f54c7..7ecc6b569cd 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/basic/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/basic/__snapshots__/output.snap.txt @@ -4,7 +4,7 @@ rspack - + diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/chunks/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/chunks/__snapshots__/output.snap.txt index a43333f636d..e1ca79897cb 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/chunks/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/chunks/__snapshots__/output.snap.txt @@ -4,7 +4,7 @@ Rspack App - + diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/favicon/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/favicon/__snapshots__/output.snap.txt index d828c24c7da..099e49a6351 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/favicon/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/favicon/__snapshots__/output.snap.txt @@ -4,7 +4,7 @@ rspack - + diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/__snapshots__/output.snap.txt index 9e0b197bbbe..f6376ba8553 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/__snapshots__/output.snap.txt @@ -4,7 +4,7 @@ rspack - + @@ -16,7 +16,7 @@ Rspack App - + diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/inject/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/inject/__snapshots__/output.snap.txt index 2bdeacf94fc..87a5eaefebb 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/inject/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/inject/__snapshots__/output.snap.txt @@ -7,7 +7,7 @@ - + ``` ```html title=inject_false.html @@ -28,7 +28,7 @@ rspack - + diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/meta/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/meta/__snapshots__/output.snap.txt index e6364084274..95cf917d497 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/meta/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/meta/__snapshots__/output.snap.txt @@ -4,7 +4,7 @@ rspack - + diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/minify/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/minify/__snapshots__/output.snap.txt index b1ee5bed9fa..6e139cbd7eb 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/minify/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/minify/__snapshots__/output.snap.txt @@ -1,3 +1,3 @@ ```html title=index.html -rspack +rspack ``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/mpa/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/mpa/__snapshots__/output.snap.txt index 23777b6ba11..3d4eb09c602 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/mpa/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/mpa/__snapshots__/output.snap.txt @@ -4,7 +4,7 @@ Rspack App - + @@ -19,7 +19,7 @@ Rspack App - + @@ -34,7 +34,7 @@ Rspack App - + diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/public-path/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/public-path/__snapshots__/output.snap.txt index 930b6f43bd1..3dda21ac059 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/public-path/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/public-path/__snapshots__/output.snap.txt @@ -4,7 +4,7 @@ rspack - + diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/template+templateParameters/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/template+templateParameters/__snapshots__/output.snap.txt index f3d5bb3958b..27e173188a5 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/template+templateParameters/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/template+templateParameters/__snapshots__/output.snap.txt @@ -4,7 +4,7 @@ bar - + diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/templateContent+templateParameters/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/templateContent+templateParameters/__snapshots__/output.snap.txt index b1201c7f560..910ed6aae49 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/templateContent+templateParameters/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/templateContent+templateParameters/__snapshots__/output.snap.txt @@ -1,5 +1,5 @@ ```html title=index.html -
bar
+
bar
``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/title/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/title/__snapshots__/output.snap.txt index 0f06bb595ec..471e9b071ed 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/title/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/title/__snapshots__/output.snap.txt @@ -4,7 +4,7 @@ Rspack title - + diff --git a/packages/rspack-test-tools/tests/configCases/builtins/html-inject/index.js b/packages/rspack-test-tools/tests/configCases/builtins/html-inject/index.js index 0dd22ce1dd1..6b5aee7329c 100644 --- a/packages/rspack-test-tools/tests/configCases/builtins/html-inject/index.js +++ b/packages/rspack-test-tools/tests/configCases/builtins/html-inject/index.js @@ -5,7 +5,7 @@ it("body-index.html inject", () => { const htmlPath = path.join(__dirname, "./body-index.html"); const htmlContent = fs.readFileSync(htmlPath, "utf-8"); expect( - htmlContent.includes('') + htmlContent.includes('') ).toBe(true); }); @@ -13,7 +13,7 @@ it("head-index.html inject", () => { const htmlPath = path.join(__dirname, "./head-index.html"); const htmlContent = fs.readFileSync(htmlPath, "utf-8"); expect( - htmlContent.includes('') + htmlContent.includes('') ).toBe(true); }); @@ -29,7 +29,7 @@ it("true-defer-index.html inject", () => { const htmlPath = path.join(__dirname, "./true-defer-index.html"); const htmlContent = fs.readFileSync(htmlPath, "utf-8"); expect( - htmlContent.includes('') + htmlContent.includes('') ).toBe(true); }); diff --git a/packages/rspack-test-tools/tests/configCases/builtins/html-public-path-auto/index.js b/packages/rspack-test-tools/tests/configCases/builtins/html-public-path-auto/index.js index 4fa871df8ad..b52676d6f32 100644 --- a/packages/rspack-test-tools/tests/configCases/builtins/html-public-path-auto/index.js +++ b/packages/rspack-test-tools/tests/configCases/builtins/html-public-path-auto/index.js @@ -4,5 +4,5 @@ const path = require("path"); it("html plugin should public path auto works", () => { const htmlPath = path.join(__dirname, "./main_page/index.html"); const htmlContent = fs.readFileSync(htmlPath, "utf-8"); - expect(htmlContent.includes('', + ], + null, + done, + ); + }); + + // TODO: support templateContent function + // it("should allow to use headTags and bodyTags directly in string literals", (done) => { + // testHtmlPlugin( + // { + // mode: "production", + // entry: path.join(__dirname, "fixtures/theme.js"), + // output: { + // path: OUTPUT_DIR, + // filename: "index_bundle.js", + // }, + // module: { + // rules: [ + // { + // test: /\.css$/, + // use: [MiniCssExtractPlugin.loader, "css-loader"], + // }, + // ], + // }, + // plugins: [ + // new MiniCssExtractPlugin({ filename: "styles.css" }), + // new HtmlWebpackPlugin({ + // scriptLoading: "blocking", + // inject: false, + // templateContent: ({ htmlWebpackPlugin }) => ` + // + // ${htmlWebpackPlugin.tags.headTags} + // ${htmlWebpackPlugin.tags.bodyTags} + // + // `, + // }), + // ], + // }, + // [ + // '', + // '', + // ], + // null, + // done, + // ); + // }); + + it("should add the javascript assets to the head for inject:true with scriptLoading:defer", (done) => { + testHtmlPlugin( + { + mode: "production", + entry: path.join(__dirname, "fixtures/theme.js"), + output: { + path: OUTPUT_DIR, + filename: "index_bundle.js", + }, + module: { + rules: [ + { + test: /\.css$/, + use: [MiniCssExtractPlugin.loader, "css-loader"], + }, + ], + }, + plugins: [ + new MiniCssExtractPlugin({ filename: "styles.css" }), + new HtmlWebpackPlugin({ + scriptLoading: "defer", + inject: true, + }), + ], + }, + [ + '', + ], + null, + done, + ); + }); + + // TODO: support templateContent function + // it("should allow to use headTags and bodyTags directly in string literals", (done) => { + // testHtmlPlugin( + // { + // mode: "production", + // entry: path.join(__dirname, "fixtures/theme.js"), + // output: { + // path: OUTPUT_DIR, + // filename: "index_bundle.js", + // }, + // module: { + // rules: [ + // { + // test: /\.css$/, + // use: [MiniCssExtractPlugin.loader, "css-loader"], + // }, + // ], + // }, + // plugins: [ + // new MiniCssExtractPlugin({ filename: "styles.css" }), + // new HtmlWebpackPlugin({ + // inject: false, + // templateContent: ({ htmlWebpackPlugin }) => ` + // + // ${htmlWebpackPlugin.tags.headTags} + // ${htmlWebpackPlugin.tags.bodyTags} + // + // `, + // }), + // ], + // }, + // [ + // '', + // ], + // null, + // done, + // ); + // }); + + it("should allow to use experiments:{outputModule:true}", (done) => { + testHtmlPlugin( + { + mode: "production", + entry: path.join(__dirname, "fixtures/index.js"), + output: { + path: OUTPUT_DIR, + filename: "index_bundle.js", + module: true, + }, + experiments: { outputModule: true }, + plugins: [new HtmlWebpackPlugin({})], + }, + [''], + null, + done, + ); + }); + + // TODO: support loader in template + // it("generates relative path for asset/resource", (done) => { + // testHtmlPlugin( + // { + // mode: "development", + // entry: path.join(__dirname, "fixtures/index.js"), + // output: { + // path: OUTPUT_DIR, + // filename: "index_bundle.js", + // assetModuleFilename: "assets/demo[ext]", + // }, + // module: { + // rules: [{ test: /\.png$/, type: "asset/resource" }], + // }, + // plugins: [ + // new HtmlWebpackPlugin({ + // template: + // "html-loader!" + path.join(__dirname, "fixtures/logo.html"), + // filename: "demo/index.js", + // }), + // ], + // }, + // [' { + // testHtmlPlugin( + // { + // mode: "development", + // entry: path.join(__dirname, "fixtures/index.js"), + // output: { + // path: OUTPUT_DIR, + // filename: "index_bundle.js", + // assetModuleFilename: "assets/demo[ext]", + // }, + // module: { + // rules: [{ test: /\.png$/, type: "asset/resource" }], + // }, + // plugins: [ + // new HtmlWebpackPlugin({ + // template: + // "html-loader!" + path.join(__dirname, "fixtures/logo.html"), + // filename: "demo/index.js", + // publicPath: "/foo/", + // }), + // ], + // }, + // [' { + testHtmlPlugin( + { + mode: "development", + entry: {}, + output: { + path: OUTPUT_DIR, + filename: "index_bundle.js", + assetModuleFilename: "assets/demo[ext]", + }, + plugins: [new HtmlWebpackPlugin({})], + }, + [""], + null, + done, + ); + }); + + // TODO: html-webpack-plugin loader + // it("allows to set custom loader interpolation settings", (done) => { + // testHtmlPlugin( + // { + // mode: "production", + // entry: { + // app: path.join(__dirname, "fixtures/index.js"), + // }, + // output: { + // path: OUTPUT_DIR, + // filename: "[name]_bundle.js", + // }, + // module: { + // rules: [ + // { + // test: /\.html$/, + // loader: require.resolve("../lib/loader.js"), + // options: { + // interpolate: /\{%=([\s\S]+?)%\}/g, + // }, + // }, + // ], + // }, + // plugins: [ + // new HtmlWebpackPlugin({ + // title: "Interpolation Demo", + // template: path.join(__dirname, "fixtures/interpolation.html"), + // }), + // ], + // }, + // ["Interpolation Demo"], + // null, + // () => { + // done(); + // }, + // ); + // }); +}); diff --git a/tests/plugin-test/html-plugin/fixtures/async.js b/tests/plugin-test/html-plugin/fixtures/async.js new file mode 100644 index 00000000000..308087a7d34 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/async.js @@ -0,0 +1,2 @@ +'use strict'; +module.exports = 'async'; diff --git a/tests/plugin-test/html-plugin/fixtures/common.js b/tests/plugin-test/html-plugin/fixtures/common.js new file mode 100644 index 00000000000..2b491f54fc7 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/common.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = 'common'; diff --git a/tests/plugin-test/html-plugin/fixtures/empty_html.html b/tests/plugin-test/html-plugin/fixtures/empty_html.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/plugin-test/html-plugin/fixtures/favicon.ico b/tests/plugin-test/html-plugin/fixtures/favicon.ico new file mode 100755 index 00000000000..be74abd69ad Binary files /dev/null and b/tests/plugin-test/html-plugin/fixtures/favicon.ico differ diff --git a/tests/plugin-test/html-plugin/fixtures/html-template-with-image.html b/tests/plugin-test/html-plugin/fixtures/html-template-with-image.html new file mode 100644 index 00000000000..5e55a3d4cbb --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/html-template-with-image.html @@ -0,0 +1,13 @@ + + + + + Test + + +

Some unique text

+
+ Logo +
+ + diff --git a/tests/plugin-test/html-plugin/fixtures/index.js b/tests/plugin-test/html-plugin/fixtures/index.js new file mode 100644 index 00000000000..dfa4d2140e0 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/index.js @@ -0,0 +1,9 @@ +'use strict'; + +require('./common'); + +// require.ensure([], function () { +require('./async'); +// }); + +document.body.innerHTML = document.body.innerHTML + '

index.js

'; diff --git a/tests/plugin-test/html-plugin/fixtures/interpolation.html b/tests/plugin-test/html-plugin/fixtures/interpolation.html new file mode 100644 index 00000000000..5647aec292b --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/interpolation.html @@ -0,0 +1,10 @@ + + + + + {%= htmlWebpackPlugin.options.title %} + + +

Some unique text

+ + diff --git a/tests/plugin-test/html-plugin/fixtures/invalid.html b/tests/plugin-test/html-plugin/fixtures/invalid.html new file mode 100644 index 00000000000..564727f09fc --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/invalid.html @@ -0,0 +1,11 @@ + + + + + Test + + +

Some unique text

+ + + diff --git a/tests/plugin-test/html-plugin/fixtures/logo.html b/tests/plugin-test/html-plugin/fixtures/logo.html new file mode 100644 index 00000000000..48e0dc0a999 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/logo.html @@ -0,0 +1,11 @@ + + + + + Example Plain file + + + + + + diff --git a/tests/plugin-test/html-plugin/fixtures/logo.png b/tests/plugin-test/html-plugin/fixtures/logo.png new file mode 100644 index 00000000000..d71b3d789f4 Binary files /dev/null and b/tests/plugin-test/html-plugin/fixtures/logo.png differ diff --git a/tests/plugin-test/html-plugin/fixtures/main.css b/tests/plugin-test/html-plugin/fixtures/main.css new file mode 100644 index 00000000000..232a2cdb3d3 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/main.css @@ -0,0 +1,3 @@ +body { + background: snow; +} \ No newline at end of file diff --git a/tests/plugin-test/html-plugin/fixtures/plain.html b/tests/plugin-test/html-plugin/fixtures/plain.html new file mode 100644 index 00000000000..13fa9b1fe8d --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/plain.html @@ -0,0 +1,9 @@ + + + + + Example Plain file + + + + diff --git a/tests/plugin-test/html-plugin/fixtures/spaced_plain.html b/tests/plugin-test/html-plugin/fixtures/spaced_plain.html new file mode 100644 index 00000000000..0c2283d5d27 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/spaced_plain.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/plugin-test/html-plugin/fixtures/src/index.ejs b/tests/plugin-test/html-plugin/fixtures/src/index.ejs new file mode 100644 index 00000000000..599e7bcd6a4 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/src/index.ejs @@ -0,0 +1,10 @@ + + + + + + src/index.ejs + + + + diff --git a/tests/plugin-test/html-plugin/fixtures/template.pug b/tests/plugin-test/html-plugin/fixtures/template.pug new file mode 100644 index 00000000000..1d303ae6c05 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/template.pug @@ -0,0 +1,9 @@ +doctype html +html + head + meta(charset="utf-8") + title Demo + body + p Some unique text + each jsFile in htmlWebpackPlugin.files.js + script(src!=jsFile) diff --git a/tests/plugin-test/html-plugin/fixtures/templateParam.cjs b/tests/plugin-test/html-plugin/fixtures/templateParam.cjs new file mode 100644 index 00000000000..32135ecb545 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/templateParam.cjs @@ -0,0 +1,21 @@ +module.exports = function (templateParams) { + const version = parseInt(process.version.match(/^v(\d+)/)[1]); + + if (typeof URL !== 'function') { + throw new Error('Error'); + } + + if (typeof URLSearchParams !== 'function') { + throw new Error('Error'); + } + + if (version >= 11 && typeof TextEncoder !== 'function') { + throw new Error('Error'); + } + + if (version >= 11 && typeof TextDecoder !== 'function') { + throw new Error('Error'); + } + + return 'templateParams keys: "' + Object.keys(templateParams).join(',') + '"'; +}; diff --git a/tests/plugin-test/html-plugin/fixtures/templateParam.js b/tests/plugin-test/html-plugin/fixtures/templateParam.js new file mode 100644 index 00000000000..32135ecb545 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/templateParam.js @@ -0,0 +1,21 @@ +module.exports = function (templateParams) { + const version = parseInt(process.version.match(/^v(\d+)/)[1]); + + if (typeof URL !== 'function') { + throw new Error('Error'); + } + + if (typeof URLSearchParams !== 'function') { + throw new Error('Error'); + } + + if (version >= 11 && typeof TextEncoder !== 'function') { + throw new Error('Error'); + } + + if (version >= 11 && typeof TextDecoder !== 'function') { + throw new Error('Error'); + } + + return 'templateParams keys: "' + Object.keys(templateParams).join(',') + '"'; +}; diff --git a/tests/plugin-test/html-plugin/fixtures/test.html b/tests/plugin-test/html-plugin/fixtures/test.html new file mode 100644 index 00000000000..3f4fd9a9493 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/test.html @@ -0,0 +1,11 @@ + + + + + Test + + +

Some unique text

+ + + diff --git a/tests/plugin-test/html-plugin/fixtures/theme.js b/tests/plugin-test/html-plugin/fixtures/theme.js new file mode 100644 index 00000000000..68f874541be --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/theme.js @@ -0,0 +1,4 @@ +'use strict'; + +require('./main.css'); +require('./index.js'); diff --git a/tests/plugin-test/html-plugin/fixtures/util.js b/tests/plugin-test/html-plugin/fixtures/util.js new file mode 100644 index 00000000000..e0bacf506c8 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/util.js @@ -0,0 +1,4 @@ +'use strict'; + +require('./common'); +document.body.innerHTML = document.body.innerHTML + '

util.js

'; diff --git a/tests/plugin-test/html-plugin/fixtures/webpackconfig.html b/tests/plugin-test/html-plugin/fixtures/webpackconfig.html new file mode 100644 index 00000000000..7d7a74f8c28 --- /dev/null +++ b/tests/plugin-test/html-plugin/fixtures/webpackconfig.html @@ -0,0 +1,11 @@ + + + + + Test + + +

Public path is <%= webpackConfig.output.publicPath %>

+ + + diff --git a/tests/plugin-test/package.json b/tests/plugin-test/package.json index 333b50857b5..0dd6cadfa1f 100644 --- a/tests/plugin-test/package.json +++ b/tests/plugin-test/package.json @@ -12,6 +12,8 @@ "@rspack/core": "workspace:*", "css-loader": "^6.11.0", "file-loader": "^6.2.0", + "html-loader": "2.1.1", + "pug-loader": "2.4.0", "sass-embedded": "^1.77.8", "sass-loader": "^16.0.0", "jsdom": "^24.0.0",