diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 1183492..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: CI -on: - # To be fixed - # push: - # branches: - # - main - # pull_request: - # branches: - # - main -jobs: - build: - name: test Node ${{ matrix.node }} ${{ matrix.os }} - timeout-minutes: 15 - - runs-on: ${{ matrix.os }} - strategy: - matrix: - node: ['18.x'] - os: [ubuntu-latest, windows-latest] - - steps: - - name: Checkout repo - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 - - - name: Use Node ${{ matrix.node }} - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6 - with: - node-version: ${{ matrix.node }} - package-manager-cache: false - - - name: Install Pnpm - uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10 - with: - run_install: true - - - name: Test - run: npm test -- --forceExit || npm test -- --forceExit || npm test -- --forceExit diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4563fbe --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: Test + +on: + pull_request: + branches: [main] + push: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Setup Node.js + uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6 + with: + node-version: 24.19.0 + package-manager-cache: false + + - name: Install Pnpm + uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10 + with: + run_install: true + + - name: Run Test + run: node --run test diff --git a/.gitignore b/.gitignore index 85be321..481f90c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules/ /dist/ /coverage/ +/examples/*/dist/ npm-debug.*.log yarn.lock package-lock.json diff --git a/examples/README.md b/examples/README.md index 22bdf5b..599b807 100644 --- a/examples/README.md +++ b/examples/README.md @@ -10,7 +10,7 @@ Custom Template | [custom-template](./custom-template) Custom Script / Link tag position | [custom-insertion-point](./custom-insertion-position) Default | [default](./default) Favicon | [favicon](./favicon.) -Html Loader | [html-loader](./html-loader) +HTML Template | [html-loader](./html-loader) Inline | [inline](./inline) Javascript-advanced | [javascript-advanced](./javascript-advanced) Javascript | [javascript](./javascript) diff --git a/examples/build-examples.js b/examples/build-examples.js deleted file mode 100644 index 0e45b0b..0000000 --- a/examples/build-examples.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * This file is just a helper to compile all examples. - * - * You could do the same by going into each example and execute - * `webpack` - */ -var webpackMajorVersion = require('webpack/package.json').version.split('.')[0]; - -var fs = require('fs'); -var path = require('path'); -var rimraf = require('rimraf'); -var webpack = require('webpack'); - -var examples = fs.readdirSync(__dirname).filter(function (file) { - return fs.statSync(path.join(__dirname, file)).isDirectory(); -}); - -examples.forEach(function (exampleName) { - var examplePath = path.join(__dirname, exampleName); - var configFile = path.join(examplePath, 'webpack.config.js'); - - var config = require(configFile); - if (Number(webpackMajorVersion) >= 4) { - config.plugins.unshift(new webpack.LoaderOptionsPlugin({ - options: { - context: process.cwd() // or the same value as `context` - } - })); - config.mode = 'production'; - config.optimization = config.optimization || {}; - config.optimization.minimizer = []; - } - - rimraf.sync(path.join(examplePath, 'dist', 'webpack-' + webpackMajorVersion)); - webpack(config, function (err, stats) { - if (err) { - console.error(err.stack || err); - if (err.details) { - console.error(err.details); - } - return; - } - - const info = stats.toJson(); - - if (stats.hasErrors()) { - console.error(info.errors); - } - - if (stats.hasWarnings()) { - console.warn(info.warnings); - } - }); -}); diff --git a/examples/build-examples.mjs b/examples/build-examples.mjs new file mode 100644 index 0000000..a2af8c3 --- /dev/null +++ b/examples/build-examples.mjs @@ -0,0 +1,54 @@ +import { readdir, rm } from 'node:fs/promises'; +import path from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; +import { rspack, rspackVersion } from '@rspack/core'; + +const examplesDirectory = fileURLToPath(new URL('.', import.meta.url)); +const rspackMajorVersion = rspackVersion.split('.')[0]; +const examples = (await readdir(examplesDirectory, { withFileTypes: true })) + .filter((entry) => entry.isDirectory()) + .map((entry) => entry.name); + +async function buildExample(exampleName) { + const examplePath = path.join(examplesDirectory, exampleName); + const configUrl = pathToFileURL(path.join(examplePath, 'rspack.config.mjs')); + const { default: config } = await import(configUrl.href); + + config.mode = 'production'; + config.optimization = config.optimization || {}; + config.optimization.minimizer = []; + + await rm(path.join(examplePath, 'dist', `rspack-${rspackMajorVersion}`), { + force: true, + recursive: true, + }); + + return new Promise((resolve, reject) => { + rspack(config, (error, stats) => { + if (error) { + reject(error); + return; + } + + if (!stats || stats.hasErrors()) { + reject( + new Error( + stats + ? stats.toString({ colors: true }) + : 'Rspack did not return compilation stats.', + ), + ); + return; + } + + resolve(); + }); + }); +} + +try { + await Promise.all(examples.map(buildExample)); +} catch (error) { + console.error(error); + process.exitCode = 1; +} diff --git a/examples/chunk-optimization/dist/webpack-5/219.js b/examples/chunk-optimization/dist/webpack-5/219.js deleted file mode 100644 index ab35797..0000000 --- a/examples/chunk-optimization/dist/webpack-5/219.js +++ /dev/null @@ -1,351 +0,0 @@ -"use strict"; -(self["webpackChunk"] = self["webpackChunk"] || []).push([[219],{ - -/***/ 609: -/***/ ((module) => { - - - -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -// css base code, injected by the css-loader -// eslint-disable-next-line func-names -module.exports = function (cssWithMappingToString) { - var list = []; // return the list of modules as css string - - list.toString = function toString() { - return this.map(function (item) { - var content = cssWithMappingToString(item); - - if (item[2]) { - return "@media ".concat(item[2], " {").concat(content, "}"); - } - - return content; - }).join(''); - }; // import a list of modules into the list - // eslint-disable-next-line func-names - - - list.i = function (modules, mediaQuery, dedupe) { - if (typeof modules === 'string') { - // eslint-disable-next-line no-param-reassign - modules = [[null, modules, '']]; - } - - var alreadyImportedModules = {}; - - if (dedupe) { - for (var i = 0; i < this.length; i++) { - // eslint-disable-next-line prefer-destructuring - var id = this[i][0]; - - if (id != null) { - alreadyImportedModules[id] = true; - } - } - } - - for (var _i = 0; _i < modules.length; _i++) { - var item = [].concat(modules[_i]); - - if (dedupe && alreadyImportedModules[item[0]]) { - // eslint-disable-next-line no-continue - continue; - } - - if (mediaQuery) { - if (!item[2]) { - item[2] = mediaQuery; - } else { - item[2] = "".concat(mediaQuery, " and ").concat(item[2]); - } - } - - list.push(item); - } - }; - - return list; -}; - -/***/ }), - -/***/ 62: -/***/ ((module, __unused_webpack_exports, __webpack_require__) => { - - - -var isOldIE = function isOldIE() { - var memo; - return function memorize() { - if (typeof memo === 'undefined') { - // Test for IE <= 9 as proposed by Browserhacks - // @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805 - // Tests for existence of standard globals is to allow style-loader - // to operate correctly into non-standard environments - // @see https://github.com/webpack-contrib/style-loader/issues/177 - memo = Boolean(window && document && document.all && !window.atob); - } - - return memo; - }; -}(); - -var getTarget = function getTarget() { - var memo = {}; - return function memorize(target) { - if (typeof memo[target] === 'undefined') { - var styleTarget = document.querySelector(target); // Special case to return head of iframe instead of iframe itself - - if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) { - try { - // This will throw an exception if access to iframe is blocked - // due to cross-origin restrictions - styleTarget = styleTarget.contentDocument.head; - } catch (e) { - // istanbul ignore next - styleTarget = null; - } - } - - memo[target] = styleTarget; - } - - return memo[target]; - }; -}(); - -var stylesInDom = []; - -function getIndexByIdentifier(identifier) { - var result = -1; - - for (var i = 0; i < stylesInDom.length; i++) { - if (stylesInDom[i].identifier === identifier) { - result = i; - break; - } - } - - return result; -} - -function modulesToDom(list, options) { - var idCountMap = {}; - var identifiers = []; - - for (var i = 0; i < list.length; i++) { - var item = list[i]; - var id = options.base ? item[0] + options.base : item[0]; - var count = idCountMap[id] || 0; - var identifier = "".concat(id, " ").concat(count); - idCountMap[id] = count + 1; - var index = getIndexByIdentifier(identifier); - var obj = { - css: item[1], - media: item[2], - sourceMap: item[3] - }; - - if (index !== -1) { - stylesInDom[index].references++; - stylesInDom[index].updater(obj); - } else { - stylesInDom.push({ - identifier: identifier, - updater: addStyle(obj, options), - references: 1 - }); - } - - identifiers.push(identifier); - } - - return identifiers; -} - -function insertStyleElement(options) { - var style = document.createElement('style'); - var attributes = options.attributes || {}; - - if (typeof attributes.nonce === 'undefined') { - var nonce = true ? __webpack_require__.nc : 0; - - if (nonce) { - attributes.nonce = nonce; - } - } - - Object.keys(attributes).forEach(function (key) { - style.setAttribute(key, attributes[key]); - }); - - if (typeof options.insert === 'function') { - options.insert(style); - } else { - var target = getTarget(options.insert || 'head'); - - if (!target) { - throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid."); - } - - target.appendChild(style); - } - - return style; -} - -function removeStyleElement(style) { - // istanbul ignore if - if (style.parentNode === null) { - return false; - } - - style.parentNode.removeChild(style); -} -/* istanbul ignore next */ - - -var replaceText = function replaceText() { - var textStore = []; - return function replace(index, replacement) { - textStore[index] = replacement; - return textStore.filter(Boolean).join('\n'); - }; -}(); - -function applyToSingletonTag(style, index, remove, obj) { - var css = remove ? '' : obj.media ? "@media ".concat(obj.media, " {").concat(obj.css, "}") : obj.css; // For old IE - - /* istanbul ignore if */ - - if (style.styleSheet) { - style.styleSheet.cssText = replaceText(index, css); - } else { - var cssNode = document.createTextNode(css); - var childNodes = style.childNodes; - - if (childNodes[index]) { - style.removeChild(childNodes[index]); - } - - if (childNodes.length) { - style.insertBefore(cssNode, childNodes[index]); - } else { - style.appendChild(cssNode); - } - } -} - -function applyToTag(style, options, obj) { - var css = obj.css; - var media = obj.media; - var sourceMap = obj.sourceMap; - - if (media) { - style.setAttribute('media', media); - } else { - style.removeAttribute('media'); - } - - if (sourceMap && typeof btoa !== 'undefined') { - css += "\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))), " */"); - } // For old IE - - /* istanbul ignore if */ - - - if (style.styleSheet) { - style.styleSheet.cssText = css; - } else { - while (style.firstChild) { - style.removeChild(style.firstChild); - } - - style.appendChild(document.createTextNode(css)); - } -} - -var singleton = null; -var singletonCounter = 0; - -function addStyle(obj, options) { - var style; - var update; - var remove; - - if (options.singleton) { - var styleIndex = singletonCounter++; - style = singleton || (singleton = insertStyleElement(options)); - update = applyToSingletonTag.bind(null, style, styleIndex, false); - remove = applyToSingletonTag.bind(null, style, styleIndex, true); - } else { - style = insertStyleElement(options); - update = applyToTag.bind(null, style, options); - - remove = function remove() { - removeStyleElement(style); - }; - } - - update(obj); - return function updateStyle(newObj) { - if (newObj) { - if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap) { - return; - } - - update(obj = newObj); - } else { - remove(); - } - }; -} - -module.exports = function (list, options) { - options = options || {}; // Force single-tag solution on IE6-9, which has a hard limit on the # of \ No newline at end of file diff --git a/examples/inline/dist/webpack-5/styles.css b/examples/inline/dist/webpack-5/styles.css deleted file mode 100644 index e86486b..0000000 --- a/examples/inline/dist/webpack-5/styles.css +++ /dev/null @@ -1,3 +0,0 @@ -body { - background: snow; -} diff --git a/examples/inline/rspack.config.mjs b/examples/inline/rspack.config.mjs new file mode 100644 index 0000000..e09397a --- /dev/null +++ b/examples/inline/rspack.config.mjs @@ -0,0 +1,32 @@ +import { getExamplePaths, HtmlRspackPlugin } from '../config.mjs'; + +const { context, outputPath } = getExamplePaths(import.meta.url); + +export default { + context, + entry: './example.js', + output: { + path: outputPath, + publicPath: '', + filename: 'bundle.js', + }, + module: { + rules: [ + { test: /\.css$/, type: 'css' }, + { test: /\.pug$/, loader: 'pug-loader' }, + ], + }, + experiments: { + css: true, + }, + plugins: [ + new HtmlRspackPlugin({ + inject: false, + cache: false, + template: 'template.pug', + filename: 'index.html', + favicon: 'favicon.ico', + title: 'pug demo', + }), + ], +}; diff --git a/examples/inline/webpack.config.js b/examples/inline/webpack.config.js deleted file mode 100755 index 752644a..0000000 --- a/examples/inline/webpack.config.js +++ /dev/null @@ -1,31 +0,0 @@ -var path = require('path'); -var HtmlWebpackPlugin = require('../..'); -var MiniCssExtractPlugin = require('mini-css-extract-plugin'); -var webpackMajorVersion = require('webpack/package.json').version.split('.')[0]; - -module.exports = { - context: __dirname, - entry: './example.js', - output: { - path: path.join(__dirname, 'dist/webpack-' + webpackMajorVersion), - publicPath: '', - filename: 'bundle.js' - }, - module: { - rules: [ - { test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] }, - { test: /\.pug$/, loader: 'pug-loader' } - ] - }, - plugins: [ - new HtmlWebpackPlugin({ - inject: false, - cache: false, - template: 'template.pug', - filename: 'index.html', - favicon: 'favicon.ico', - title: 'pug demo' - }), - new MiniCssExtractPlugin({ filename: 'styles.css' }) - ] -}; diff --git a/examples/javascript-advanced/dist/webpack-5/55b19870aff2e53d1fb1.png b/examples/javascript-advanced/dist/webpack-5/55b19870aff2e53d1fb1.png deleted file mode 100644 index d71b3d7..0000000 Binary files a/examples/javascript-advanced/dist/webpack-5/55b19870aff2e53d1fb1.png and /dev/null differ diff --git a/examples/javascript-advanced/dist/webpack-5/bundle.js b/examples/javascript-advanced/dist/webpack-5/bundle.js deleted file mode 100644 index 235bdd8..0000000 --- a/examples/javascript-advanced/dist/webpack-5/bundle.js +++ /dev/null @@ -1,81 +0,0 @@ -/* - * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). - * This devtool is neither made for production nor for readable output files. - * It uses "eval()" calls to create a separate source file in the browser devtools. - * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) - * or disable the default devtool with "devtool: false". - * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). - */ -/******/ (() => { // webpackBootstrap -/******/ var __webpack_modules__ = ({ - -/***/ 144: -/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { - -eval("__webpack_require__(636);\n\nvar universal = __webpack_require__(184);\nvar h1 = document.createElement('h1');\nh1.innerHTML = universal();\n\ndocument.body.appendChild(h1);\n\n\n//# sourceURL=webpack:///./example.js?"); - -/***/ }), - -/***/ 184: -/***/ ((module) => { - -"use strict"; -eval("// This file is used for frontend and backend\n\n\n// If compiled by the html-webpack-plugin\n// HTML_WEBPACK_PLUGIN is set to true:\nvar backend = typeof HTML_WEBPACK_PLUGIN !== 'undefined';\n\nmodule.exports = function () {\n return 'Hello World from ' + (backend ? 'backend' : 'frontend');\n};\n\n\n//# sourceURL=webpack:///./universial.js?"); - -/***/ }), - -/***/ 636: -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n// extracted by mini-css-extract-plugin\n\n\n//# sourceURL=webpack:///./main.css?"); - -/***/ }) - -/******/ }); -/************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ // Check if module is in cache -/******/ var cachedModule = __webpack_module_cache__[moduleId]; -/******/ if (cachedModule !== undefined) { -/******/ return cachedModule.exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/************************************************************************/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __webpack_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ })(); -/******/ -/************************************************************************/ -/******/ -/******/ // startup -/******/ // Load entry module and return exports -/******/ // This entry module can't be inlined because the eval devtool is used. -/******/ var __webpack_exports__ = __webpack_require__(144); -/******/ -/******/ })() -; \ No newline at end of file diff --git a/examples/javascript-advanced/dist/webpack-5/index.html b/examples/javascript-advanced/dist/webpack-5/index.html deleted file mode 100644 index 216fe10..0000000 --- a/examples/javascript-advanced/dist/webpack-5/index.html +++ /dev/null @@ -1 +0,0 @@ -Webpack AppHello World from backend -

Partial

\ No newline at end of file diff --git a/examples/javascript-advanced/dist/webpack-5/styles.css b/examples/javascript-advanced/dist/webpack-5/styles.css deleted file mode 100644 index e86486b..0000000 --- a/examples/javascript-advanced/dist/webpack-5/styles.css +++ /dev/null @@ -1,3 +0,0 @@ -body { - background: snow; -} diff --git a/examples/javascript-advanced/rspack.config.mjs b/examples/javascript-advanced/rspack.config.mjs new file mode 100644 index 0000000..2aef2f9 --- /dev/null +++ b/examples/javascript-advanced/rspack.config.mjs @@ -0,0 +1,29 @@ +import { getExamplePaths, HtmlRspackPlugin } from '../config.mjs'; + +const { context, outputPath } = getExamplePaths(import.meta.url); + +export default { + context, + entry: './example.js', + output: { + path: outputPath, + publicPath: '', + filename: 'bundle.js', + }, + module: { + rules: [ + { test: /\.css$/, type: 'css' }, + { test: /\.png$/, type: 'asset/resource' }, + { test: /partial\.html$/, type: 'asset/source' }, + ], + }, + experiments: { + css: true, + }, + devtool: 'eval', + plugins: [ + new HtmlRspackPlugin({ + template: 'template.js', + }), + ], +}; diff --git a/examples/javascript-advanced/template.js b/examples/javascript-advanced/template.js index 2b006a2..9c9aca0 100644 --- a/examples/javascript-advanced/template.js +++ b/examples/javascript-advanced/template.js @@ -1,5 +1,5 @@ -// Webpack require: -var partial = require('./partial.html').default; +// Rspack require: +var partial = require('./partial.html'); var universal = require('./universial.js'); // Export a function / promise / or a string: diff --git a/examples/javascript-advanced/webpack.config.js b/examples/javascript-advanced/webpack.config.js deleted file mode 100644 index a8e1af6..0000000 --- a/examples/javascript-advanced/webpack.config.js +++ /dev/null @@ -1,28 +0,0 @@ -var path = require('path'); -var HtmlWebpackPlugin = require('../..'); -var MiniCssExtractPlugin = require('mini-css-extract-plugin'); -var webpackMajorVersion = require('webpack/package.json').version.split('.')[0]; - -module.exports = { - context: __dirname, - entry: './example.js', - output: { - path: path.join(__dirname, 'dist/webpack-' + webpackMajorVersion), - publicPath: '', - filename: 'bundle.js' - }, - module: { - rules: [ - { test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] }, - { test: /\.png$/, type: 'asset/resource' }, - { test: /\.html$/, loader: 'html-loader' } - ] - }, - devtool: 'eval', - plugins: [ - new HtmlWebpackPlugin({ - template: 'template.js' - }), - new MiniCssExtractPlugin({ filename: 'styles.css' }) - ] -}; diff --git a/examples/javascript/dist/webpack-5/55b19870aff2e53d1fb1.png b/examples/javascript/dist/webpack-5/55b19870aff2e53d1fb1.png deleted file mode 100644 index d71b3d7..0000000 Binary files a/examples/javascript/dist/webpack-5/55b19870aff2e53d1fb1.png and /dev/null differ diff --git a/examples/javascript/dist/webpack-5/bundle.js b/examples/javascript/dist/webpack-5/bundle.js deleted file mode 100644 index d6c3e3c..0000000 --- a/examples/javascript/dist/webpack-5/bundle.js +++ /dev/null @@ -1,85 +0,0 @@ -/******/ (() => { // webpackBootstrap -/******/ var __webpack_modules__ = ({ - -/***/ 184: -/***/ ((module) => { - -"use strict"; -// This file is used for frontend and backend - - -// If compiled by the html-webpack-plugin -// HTML_WEBPACK_PLUGIN is set to true: -var backend = typeof HTML_WEBPACK_PLUGIN !== 'undefined'; - -module.exports = function () { - return 'Hello World from ' + (backend ? 'backend' : 'frontend'); -}; - - -/***/ }), - -/***/ 636: -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -// extracted by mini-css-extract-plugin - - -/***/ }) - -/******/ }); -/************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ // Check if module is in cache -/******/ var cachedModule = __webpack_module_cache__[moduleId]; -/******/ if (cachedModule !== undefined) { -/******/ return cachedModule.exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/************************************************************************/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __webpack_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ })(); -/******/ -/************************************************************************/ -var __webpack_exports__ = {}; -// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. -(() => { -__webpack_require__(636); - -var universal = __webpack_require__(184); -var h1 = document.createElement('h1'); -h1.innerHTML = universal(); - -document.body.appendChild(h1); - -})(); - -/******/ })() -; \ No newline at end of file diff --git a/examples/javascript/dist/webpack-5/index.html b/examples/javascript/dist/webpack-5/index.html deleted file mode 100644 index 0f3de26..0000000 --- a/examples/javascript/dist/webpack-5/index.html +++ /dev/null @@ -1 +0,0 @@ -Hello World from backend2023-04-14T18:14:20.006Z

Partial

\ No newline at end of file diff --git a/examples/javascript/dist/webpack-5/styles.css b/examples/javascript/dist/webpack-5/styles.css deleted file mode 100644 index e86486b..0000000 --- a/examples/javascript/dist/webpack-5/styles.css +++ /dev/null @@ -1,3 +0,0 @@ -body { - background: snow; -} diff --git a/examples/javascript/rspack.config.mjs b/examples/javascript/rspack.config.mjs new file mode 100644 index 0000000..ffbc0a6 --- /dev/null +++ b/examples/javascript/rspack.config.mjs @@ -0,0 +1,27 @@ +import { getExamplePaths, HtmlRspackPlugin } from '../config.mjs'; + +const { context, outputPath } = getExamplePaths(import.meta.url); + +export default { + context, + entry: './example.js', + output: { + path: outputPath, + filename: 'bundle.js', + }, + module: { + rules: [ + { test: /\.css$/, type: 'css' }, + { test: /\.png$/, type: 'asset/resource' }, + { test: /partial\.html$/, type: 'asset/source' }, + ], + }, + experiments: { + css: true, + }, + plugins: [ + new HtmlRspackPlugin({ + template: 'template.js', + }), + ], +}; diff --git a/examples/javascript/template.js b/examples/javascript/template.js index 33ca1b5..8cb1e19 100644 --- a/examples/javascript/template.js +++ b/examples/javascript/template.js @@ -1,5 +1,5 @@ -// Webpack require: -var partial = require('./partial.html').default; +// Rspack require: +var partial = require('./partial.html'); var universal = require('./universial.js'); // Export a function / promise / or a string: diff --git a/examples/javascript/webpack.config.js b/examples/javascript/webpack.config.js deleted file mode 100644 index 9945c4c..0000000 --- a/examples/javascript/webpack.config.js +++ /dev/null @@ -1,25 +0,0 @@ -var path = require('path'); -var HtmlWebpackPlugin = require('../..'); -var MiniCssExtractPlugin = require('mini-css-extract-plugin'); -var webpackMajorVersion = require('webpack/package.json').version.split('.')[0]; -module.exports = { - context: __dirname, - entry: './example.js', - output: { - path: path.join(__dirname, 'dist/webpack-' + webpackMajorVersion), - filename: 'bundle.js' - }, - module: { - rules: [ - { test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] }, - { test: /\.png$/, type: 'asset/resource' }, - { test: /\.html$/, loader: 'html-loader' } - ] - }, - plugins: [ - new HtmlWebpackPlugin({ - template: 'template.js' - }), - new MiniCssExtractPlugin({ filename: 'styles.css' }) - ] -}; diff --git a/examples/multi-page/dist/webpack-5/first.html b/examples/multi-page/dist/webpack-5/first.html deleted file mode 100644 index 930ee6e..0000000 --- a/examples/multi-page/dist/webpack-5/first.html +++ /dev/null @@ -1 +0,0 @@ -Webpack App \ No newline at end of file diff --git a/examples/multi-page/dist/webpack-5/first.js b/examples/multi-page/dist/webpack-5/first.js deleted file mode 100644 index 9c240c9..0000000 --- a/examples/multi-page/dist/webpack-5/first.js +++ /dev/null @@ -1,484 +0,0 @@ -/******/ (() => { // webpackBootstrap -/******/ var __webpack_modules__ = ({ - -/***/ 173: -/***/ ((module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ Z: () => (__WEBPACK_DEFAULT_EXPORT__) -/* harmony export */ }); -/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(609); -/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0__); -// Imports - -var ___CSS_LOADER_EXPORT___ = _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0___default()(function(i){return i[1]}); -// Module -___CSS_LOADER_EXPORT___.push([module.id, "body {\n background: snow;\n}", ""]); -// Exports -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (___CSS_LOADER_EXPORT___); - - -/***/ }), - -/***/ 609: -/***/ ((module) => { - -"use strict"; - - -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -// css base code, injected by the css-loader -// eslint-disable-next-line func-names -module.exports = function (cssWithMappingToString) { - var list = []; // return the list of modules as css string - - list.toString = function toString() { - return this.map(function (item) { - var content = cssWithMappingToString(item); - - if (item[2]) { - return "@media ".concat(item[2], " {").concat(content, "}"); - } - - return content; - }).join(''); - }; // import a list of modules into the list - // eslint-disable-next-line func-names - - - list.i = function (modules, mediaQuery, dedupe) { - if (typeof modules === 'string') { - // eslint-disable-next-line no-param-reassign - modules = [[null, modules, '']]; - } - - var alreadyImportedModules = {}; - - if (dedupe) { - for (var i = 0; i < this.length; i++) { - // eslint-disable-next-line prefer-destructuring - var id = this[i][0]; - - if (id != null) { - alreadyImportedModules[id] = true; - } - } - } - - for (var _i = 0; _i < modules.length; _i++) { - var item = [].concat(modules[_i]); - - if (dedupe && alreadyImportedModules[item[0]]) { - // eslint-disable-next-line no-continue - continue; - } - - if (mediaQuery) { - if (!item[2]) { - item[2] = mediaQuery; - } else { - item[2] = "".concat(mediaQuery, " and ").concat(item[2]); - } - } - - list.push(item); - } - }; - - return list; -}; - -/***/ }), - -/***/ 965: -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) -/* harmony export */ }); -/* harmony import */ var _node_modules_style_loader_dist_runtime_injectStylesIntoStyleTag_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(62); -/* harmony import */ var _node_modules_style_loader_dist_runtime_injectStylesIntoStyleTag_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_style_loader_dist_runtime_injectStylesIntoStyleTag_js__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _node_modules_css_loader_dist_cjs_js_main_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(173); - - - -var options = {}; - -options.insert = "head"; -options.singleton = false; - -var update = _node_modules_style_loader_dist_runtime_injectStylesIntoStyleTag_js__WEBPACK_IMPORTED_MODULE_0___default()(_node_modules_css_loader_dist_cjs_js_main_css__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .Z, options); - - - -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_node_modules_css_loader_dist_cjs_js_main_css__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .Z.locals || {}); - -/***/ }), - -/***/ 62: -/***/ ((module, __unused_webpack_exports, __webpack_require__) => { - -"use strict"; - - -var isOldIE = function isOldIE() { - var memo; - return function memorize() { - if (typeof memo === 'undefined') { - // Test for IE <= 9 as proposed by Browserhacks - // @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805 - // Tests for existence of standard globals is to allow style-loader - // to operate correctly into non-standard environments - // @see https://github.com/webpack-contrib/style-loader/issues/177 - memo = Boolean(window && document && document.all && !window.atob); - } - - return memo; - }; -}(); - -var getTarget = function getTarget() { - var memo = {}; - return function memorize(target) { - if (typeof memo[target] === 'undefined') { - var styleTarget = document.querySelector(target); // Special case to return head of iframe instead of iframe itself - - if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) { - try { - // This will throw an exception if access to iframe is blocked - // due to cross-origin restrictions - styleTarget = styleTarget.contentDocument.head; - } catch (e) { - // istanbul ignore next - styleTarget = null; - } - } - - memo[target] = styleTarget; - } - - return memo[target]; - }; -}(); - -var stylesInDom = []; - -function getIndexByIdentifier(identifier) { - var result = -1; - - for (var i = 0; i < stylesInDom.length; i++) { - if (stylesInDom[i].identifier === identifier) { - result = i; - break; - } - } - - return result; -} - -function modulesToDom(list, options) { - var idCountMap = {}; - var identifiers = []; - - for (var i = 0; i < list.length; i++) { - var item = list[i]; - var id = options.base ? item[0] + options.base : item[0]; - var count = idCountMap[id] || 0; - var identifier = "".concat(id, " ").concat(count); - idCountMap[id] = count + 1; - var index = getIndexByIdentifier(identifier); - var obj = { - css: item[1], - media: item[2], - sourceMap: item[3] - }; - - if (index !== -1) { - stylesInDom[index].references++; - stylesInDom[index].updater(obj); - } else { - stylesInDom.push({ - identifier: identifier, - updater: addStyle(obj, options), - references: 1 - }); - } - - identifiers.push(identifier); - } - - return identifiers; -} - -function insertStyleElement(options) { - var style = document.createElement('style'); - var attributes = options.attributes || {}; - - if (typeof attributes.nonce === 'undefined') { - var nonce = true ? __webpack_require__.nc : 0; - - if (nonce) { - attributes.nonce = nonce; - } - } - - Object.keys(attributes).forEach(function (key) { - style.setAttribute(key, attributes[key]); - }); - - if (typeof options.insert === 'function') { - options.insert(style); - } else { - var target = getTarget(options.insert || 'head'); - - if (!target) { - throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid."); - } - - target.appendChild(style); - } - - return style; -} - -function removeStyleElement(style) { - // istanbul ignore if - if (style.parentNode === null) { - return false; - } - - style.parentNode.removeChild(style); -} -/* istanbul ignore next */ - - -var replaceText = function replaceText() { - var textStore = []; - return function replace(index, replacement) { - textStore[index] = replacement; - return textStore.filter(Boolean).join('\n'); - }; -}(); - -function applyToSingletonTag(style, index, remove, obj) { - var css = remove ? '' : obj.media ? "@media ".concat(obj.media, " {").concat(obj.css, "}") : obj.css; // For old IE - - /* istanbul ignore if */ - - if (style.styleSheet) { - style.styleSheet.cssText = replaceText(index, css); - } else { - var cssNode = document.createTextNode(css); - var childNodes = style.childNodes; - - if (childNodes[index]) { - style.removeChild(childNodes[index]); - } - - if (childNodes.length) { - style.insertBefore(cssNode, childNodes[index]); - } else { - style.appendChild(cssNode); - } - } -} - -function applyToTag(style, options, obj) { - var css = obj.css; - var media = obj.media; - var sourceMap = obj.sourceMap; - - if (media) { - style.setAttribute('media', media); - } else { - style.removeAttribute('media'); - } - - if (sourceMap && typeof btoa !== 'undefined') { - css += "\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))), " */"); - } // For old IE - - /* istanbul ignore if */ - - - if (style.styleSheet) { - style.styleSheet.cssText = css; - } else { - while (style.firstChild) { - style.removeChild(style.firstChild); - } - - style.appendChild(document.createTextNode(css)); - } -} - -var singleton = null; -var singletonCounter = 0; - -function addStyle(obj, options) { - var style; - var update; - var remove; - - if (options.singleton) { - var styleIndex = singletonCounter++; - style = singleton || (singleton = insertStyleElement(options)); - update = applyToSingletonTag.bind(null, style, styleIndex, false); - remove = applyToSingletonTag.bind(null, style, styleIndex, true); - } else { - style = insertStyleElement(options); - update = applyToTag.bind(null, style, options); - - remove = function remove() { - removeStyleElement(style); - }; - } - - update(obj); - return function updateStyle(newObj) { - if (newObj) { - if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap) { - return; - } - - update(obj = newObj); - } else { - remove(); - } - }; -} - -module.exports = function (list, options) { - options = options || {}; // Force single-tag solution on IE6-9, which has a hard limit on the # of