diff --git a/.cspell.json b/.cspell.json new file mode 100644 index 00000000..962a540b --- /dev/null +++ b/.cspell.json @@ -0,0 +1,58 @@ +{ + "version": "0.2", + "language": "en,en-gb", + "words": [ + "lastname", + "firstname", + "memfs", + "ASCIIC", + "xlink", + "imagesrcset", + "Requestable", + "Itemprop", + "itemprop", + "layoutimage", + "installurl", + "embedurl", + "duringmedia", + "downloadurl", + "contenturl", + "thumbnailurl", + "tileimage", + "Rels", + "precomposed", + "cssnano", + "requestify", + "substeps", + "srcset", + "scrset", + "plusplus", + "webp", + "Webp", + "layoutimage", + "msapplication", + "hspace", + "vspace", + "jsbeautify", + "Gitter", + "commitlint", + "postprocessor", + "eslintcache", + "cspellcache" + ], + "ignorePaths": [ + "CHANGELOG.md", + "package.json", + "dist/**", + "**/__snapshots__/**", + "package-lock.json", + "*.xml", + "*.ogg", + "*.html", + "*.webp", + "node_modules", + "coverage", + "*.log", + "test/outputs/url/**" + ] +} diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index c52afd16..00000000 --- a/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -/coverage -/dist -/node_modules -/test/fixtures \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 095ce2a5..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - root: true, - extends: ['@webpack-contrib/eslint-config-webpack', 'prettier'], -}; diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index d6d67e15..0bee8707 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -17,9 +17,9 @@ The issue tracker is for bug reports and feature discussions. ## Found an Issue or Bug? -Before you submit an issue, please search the issue tracker, maybe an issue for your problem already exists and the discussion might inform you of workarounds readily available. +Before you submit an issue, please search the issue tracker, an issue for your problem may already exist, and the discussion might inform you of workarounds readily available. -We want to fix all the issues as soon as possible, but before fixing a bug we need to reproduce and confirm it. In order to reproduce bugs, we ask that you to provide a minimal reproduction scenario (github repo or failing test case). Having a live, reproducible scenario gives us a wealth of important information without going back & forth to you with additional questions like: +We want to fix all the issues as soon as possible, but before fixing a bug, we need to reproduce and confirm it. In order to reproduce bugs, we ask that you provide a minimal reproduction scenario (GitHub repo or failing test case). Having a live, reproducible scenario gives us a wealth of important information without going back & forth to you with additional questions like: - version of Webpack used - version of the loader / plugin you are creating a bug report for @@ -27,24 +27,24 @@ We want to fix all the issues as soon as possible, but before fixing a bug we ne A minimal reproduce scenario allows us to quickly confirm a bug (or point out config problems) as well as confirm that we are fixing the right problem. -We will be insisting on a minimal reproduce scenario in order to save maintainers time and ultimately be able to fix more bugs. We understand that sometimes it might be hard to extract essentials bits of code from a larger code-base but we really need to isolate the problem before we can fix it. +We will be insisting on a minimal reproduction scenario in order to save the maintainers' time and ultimately be able to fix more bugs. We understand that sometimes it might be hard to extract essential bits of code from a larger codebase, but we really need to isolate the problem before we can fix it. -Unfortunately, we are not able to investigate / fix bugs without a minimal reproduction, so if we don't hear back from you we are going to close an issue that doesn't have enough info to be reproduced. +Unfortunately, we are unable to investigate or fix bugs without a minimal reproduction, so if we don't hear back from you, we may have to close an issue that doesn't have enough info to be reproduced. ## Feature Requests? -You can _request_ a new feature by creating an issue on Github. +You can _request_ a new feature by creating an issue on GitHub. -If you would like to _implement_ a new feature, please submit an issue with a proposal for your work `first`, to be sure that particular makes sense for the project. +If you would like to _implement_ a new feature yourself, please **first submit an issue** with a proposal to ensure the idea aligns with the goals of the project. ## Pull Request Submission Guidelines Before you submit your Pull Request (PR) consider the following guidelines: -- Search Github for an open or closed PR that relates to your submission. You don't want to duplicate effort. -- Commit your changes using a descriptive commit message that follows our [commit message conventions](#commit). Adherence to these conventions is necessary because release notes are automatically generated from these messages. -- Fill out our `Pull Request Template`. Your pull request will not be considered if it is ignored. -- Please sign the `Contributor License Agreement (CLA)` when a pull request is opened. We cannot accept your pull request without this. Make sure you sign with the primary email address associated with your local / github account. +- Search GitHub for an open or closed PR related to your submission to avoid duplicating effort. +- Commit your changes using a descriptive commit message that follows our [commit message conventions](#commit). This is important because release notes are automatically generated from these messages. +- Complete the `Pull Request Template`. Pull requests that ignore the template will not be reviewed. +- Please sign the `Contributor License Agreement (CLA)` when you open your pull request. We cannot accept your contribution without it. Be sure to sign using the primary email address associated with your local and GitHub account. ## Webpack Contrib Commit Conventions @@ -61,8 +61,7 @@ format that includes a **type**, a **scope** and a **subject**: The **header** is mandatory and the **scope** of the header is optional. -Any line of the commit message cannot be longer 100 characters! This allows the message to be easier -to read on GitHub as well as in various git tools. +No line in the commit message should exceed 100 characters! This makes the message easier to read on GitHub as well as in various Git tools. The footer should contain a [closing reference to an issue](https://help.github.com/articles/closing-issues-via-commit-messages/) if any. @@ -83,7 +82,7 @@ In the body it should say: `This reverts commit .`, where the hash is the ### Type -Must be one of the following: +Must be one of the following commit types: - **build**: Changes that affect the build system or external dependencies (example scopes: babel, npm) - **chore**: Changes that fall outside of build / docs that do not effect source code (example scopes: package, defaults) @@ -99,27 +98,26 @@ Must be one of the following: ### Scope -The scope is subjective & depends on the `type` see above. A good example would be a change to a particular class / module. +The scope is subjective & depends on the `type` see above. A good example of a scope would be a change to a particular class or module. ### Subject The subject contains a succinct description of the change: -- use the imperative, present tense: "change" not "changed" nor "changes" +- use the imperative, present tense: "change" not "changed" or "changes" - don't capitalize the first letter - no dot (.) at the end ### Body -Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes". -The body should include the motivation for the change and contrast this with previous behavior. +Just as in the **subject**, use the imperative, present tense: "change" not "changed" or "changes". +The body should include the motivation for the change and contrast it with previous behavior. ### Footer -The footer should contain any information about **Breaking Changes** and is also the place to -reference GitHub issues that this commit **Closes**. +The footer should include any information about **Breaking Changes** and is also the place to reference GitHub issues that this commit **Closes**. -**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this. +**Breaking Changes** must start with the word `BREAKING CHANGE:` followed by a space or two new lines. The rest of the breaking change details should be provided after this. Example @@ -133,9 +131,7 @@ Migration: see webpack/webpack#5225 ## Testing Your Pull Request -You may have the need to test your changes in a real-world project or dependent -module. Thankfully, Github provides a means to do this. Add a dependency to the -`package.json` for such a project as follows: +You may need to test your changes in a real-world project or a dependent module. Thankfully, GitHub provides a means to do this. To add a dependency to the `package.json` of such a project, use the following syntax: ```json { @@ -149,11 +145,11 @@ Where `{id}` is the # ID of your Pull Request. ## Contributor License Agreement -When submitting your contribution, a CLA (Contributor License Agreement) bot will come by to verify that you signed the [CLA](https://cla.js.foundation/ryanclark/html-loader). +When submitting your contribution, a CLA (Contributor License Agreement) bot will verify whether you have signed the [CLA](https://easycla.lfx.linuxfoundation.org/#/?version=2). If it is your first time, it will link you to the right place to sign it. -However, if you have committed your contributions using an email that is not the same as your email used on GitHub, the CLA bot can't accept your contribution. +However, if the email used in your commits doesn’t match the email associated with your GitHub account, the CLA bot won’t accept your contribution. -Run `git config user.email` to see your Git email, and verify it with [your GitHub email](https://github.com/settings/emails). +Run `Git config user.email` to see your Git email, and verify it with [your GitHub email](https://github.com/settings/emails). ## Thanks diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index f68cbd3e..f92d3cb0 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,16 +1,15 @@ diff --git a/.github/ISSUE_TEMPLATE/BUG.md b/.github/ISSUE_TEMPLATE/BUG.md index b3633bb6..931d2e2e 100644 --- a/.github/ISSUE_TEMPLATE/BUG.md +++ b/.github/ISSUE_TEMPLATE/BUG.md @@ -3,48 +3,31 @@ name: πŸ› Bug Report about: Something went awry and you'd like to tell us about it. --- - + - If you remove or skip this template, you'll make the 🐼 sad and the mighty god - of Github will appear and pile-drive the close button from a great height - while making animal noises. +### Bug report - πŸ‘‰πŸ½ Need support, advice, or help? Don't open an issue! - Head to StackOverflow or https://gitter.im/webpack/webpack. ---> - -- Operating System: -- Node Version: -- NPM Version: -- webpack Version: -- html-loader Version: - -### Expected Behavior - - + + + + ### Actual Behavior - - -### Code + -```js -// webpack.config.js -// If your code blocks are over 20 lines, please paste a link to a gist -// (https://gist.github.com). -``` +### Expected Behavior -```js -// additional code, HEY YO remove this block if you don't need it -``` + + ### How Do We Reproduce? - + + + + - If your webpack config is over 50 lines long, please provide a URL to a repo - for your beefy πŸ– app that we can use to reproduce. ---> +### Please paste the results of `npx webpack-cli info` here, and mention other relevant information. diff --git a/.github/ISSUE_TEMPLATE/DOCS.md b/.github/ISSUE_TEMPLATE/DOCS.md index 88d05ddd..1f9fad79 100644 --- a/.github/ISSUE_TEMPLATE/DOCS.md +++ b/.github/ISSUE_TEMPLATE/DOCS.md @@ -3,20 +3,12 @@ name: πŸ“š Documentation about: Are the docs lacking or missing something? Do they need some new πŸ”₯ hotness? Tell us here. --- - + - If you remove or skip this template, you'll make the 🐼 sad and the mighty god - of Github will appear and pile-drive the close button from a great height - while making animal noises. +Documentation is: - πŸ‘‰πŸ½ Need support, advice, or help? Don't open an issue! - Head to StackOverflow or https://gitter.im/webpack/webpack. ---> - -Documentation Is: - - + - [ ] Missing - [ ] Needed @@ -25,4 +17,9 @@ Documentation Is: ### Please Explain in Detail... + + + + + ### Your Proposal for Changes diff --git a/.github/ISSUE_TEMPLATE/FEATURE.md b/.github/ISSUE_TEMPLATE/FEATURE.md index cb894534..d1e618fe 100644 --- a/.github/ISSUE_TEMPLATE/FEATURE.md +++ b/.github/ISSUE_TEMPLATE/FEATURE.md @@ -3,23 +3,18 @@ name: ✨ Feature Request about: Suggest an idea for this project --- - + - If you remove or skip this template, you'll make the 🐼 sad and the mighty god - of Github will appear and pile-drive the close button from a great height - while making animal noises. +### Feature Proposal - πŸ‘‰πŸ½ Need support, advice, or help? Don't open an issue! - Head to StackOverflow or https://gitter.im/webpack/webpack. ---> + + + + -- Operating System: -- Node Version: -- NPM Version: -- webpack Version: -- html-loader Version: +### Feature Use Case -### Feature Proposal + -### Feature Use Case +### Please paste the results of `npx webpack-cli info` here, and mention other relevant information. diff --git a/.github/ISSUE_TEMPLATE/MODIFICATION.md b/.github/ISSUE_TEMPLATE/MODIFICATION.md index aeb2d4b2..35602449 100644 --- a/.github/ISSUE_TEMPLATE/MODIFICATION.md +++ b/.github/ISSUE_TEMPLATE/MODIFICATION.md @@ -1,27 +1,25 @@ --- name: πŸ”§ Modification Request -about: Would you like something work differently? Have an alternative approach? This is the template for you. +about: Want something to work differently? Have an alternative approach? This is the template for you. --- - + - If you remove or skip this template, you'll make the 🐼 sad and the mighty god - of Github will appear and pile-drive the close button from a great height - while making animal noises. - - πŸ‘‰πŸ½ Need support, advice, or help? Don't open an issue! - Head to StackOverflow or https://gitter.im/webpack/webpack. ---> +### Modification Proposal -- Operating System: -- Node Version: -- NPM Version: -- webpack Version: -- html-loader Version: + + + + + ### Expected Behavior / Situation + + ### Actual Behavior / Situation -### Modification Proposal + + +### Please paste the results of `npx webpack-cli info` here, and mention other relevant information. diff --git a/.github/ISSUE_TEMPLATE/SUPPORT.md b/.github/ISSUE_TEMPLATE/SUPPORT.md index 558934ac..066348a5 100644 --- a/.github/ISSUE_TEMPLATE/SUPPORT.md +++ b/.github/ISSUE_TEMPLATE/SUPPORT.md @@ -1,8 +1,15 @@ --- name: πŸ†˜ Support, Help, and Advice -about: πŸ‘‰πŸ½ Need support, help, or advice? Don't open an issue! Head to StackOverflow or https://gitter.im/webpack/webpack. +about: πŸ‘‰πŸ½ Need support, help, or advice? Don't open an issue - visit "GitHub Discussions" or "Stack Overflow" instead. --- -Hey there! If you need support, help, or advice then this is not the place to ask. -Please visit [StackOverflow](https://stackoverflow.com/questions/tagged/webpack) -or [the Webpack Gitter](https://gitter.im/webpack/webpack) instead. +Hey there! πŸ‘‹ + +If you need support, help, or advice then this is not the right place to ask. + +Please visit one of the following instead: + +- [GitHub Discussions](https://github.com/webpack/webpack/discussions) +- [Stack Overflow](https://stackoverflow.com/questions/tagged/webpack) + +Thanks for understanding! diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 00000000..21aaefe0 --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,14 @@ +name: "Dependency Review" +on: [pull_request] + +permissions: + contents: read + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: "Checkout Repository" + uses: actions/checkout@v5 + - name: "Dependency Review" + uses: actions/dependency-review-action@v4 diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index a375f69f..2f99920c 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -10,6 +10,9 @@ on: - master - next +permissions: + contents: read + jobs: lint: name: Lint - ${{ matrix.os }} - Node v${{ matrix.node-version }} @@ -20,22 +23,24 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node-version: [12.x] + node-version: [lts/*] runs-on: ${{ matrix.os }} + concurrency: + group: lint-${{ matrix.os }}-v${{ matrix.node-version }}-${{ github.ref }} + cancel-in-progress: true + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 with: fetch-depth: 0 - - name: Use Node.js ${{ env.node-version }} - uses: actions/setup-node@v1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 with: - node-version: ${{ env.node-version }} - - - name: Use latest NPM - run: sudo npm i -g npm + node-version: ${{ matrix.node-version }} + cache: "npm" - name: Install dependencies run: npm ci @@ -46,8 +51,9 @@ jobs: # - name: Security audit # run: npm run security - - name: Check commit message - uses: wagoid/commitlint-github-action@v1 + - name: Validate PR commits with commitlint + if: github.event_name == 'pull_request' + run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose test: name: Test - ${{ matrix.os }} - Node v${{ matrix.node-version }}, Webpack ${{ matrix.webpack-version }} @@ -55,41 +61,39 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [10.x, 12.x, 14.x] + node-version: [18.x, 20.x, 22.x, 24.x] webpack-version: [latest] runs-on: ${{ matrix.os }} + concurrency: + group: test-${{ matrix.os }}-v${{ matrix.node-version }}-${{ matrix.webpack-version }}-${{ github.ref }} + cancel-in-progress: true + steps: - name: Setup Git if: matrix.os == 'windows-latest' run: git config --global core.autocrlf input - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - - - name: Use latest NPM on ubuntu/macos - if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' - run: sudo npm i -g npm - - - name: Use latest NPM on windows - if: matrix.os == 'windows-latest' - run: npm i -g npm + cache: "npm" - name: Install dependencies run: npm ci - name: Install webpack ${{ matrix.webpack-version }} + if: matrix.webpack-version != 'latest' run: npm i webpack@${{ matrix.webpack-version }} - name: Run tests for webpack version ${{ matrix.webpack-version }} run: npm run test:coverage -- --ci - name: Submit coverage data to codecov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 76df9327..32ba562b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ logs *.log npm-debug.log* .eslintcache +.cspellcache /coverage /dist /local diff --git a/.husky/.gitignore b/.husky/.gitignore deleted file mode 100644 index c9cdc63b..00000000 --- a/.husky/.gitignore +++ /dev/null @@ -1 +0,0 @@ -_ \ No newline at end of file diff --git a/.husky/commit-msg b/.husky/commit-msg index 5426a932..dbce4f4c 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npx commitlint --edit $1 +commitlint --edit $1 diff --git a/.husky/pre-commit b/.husky/pre-commit index 36af2198..c27d8893 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npx lint-staged +lint-staged diff --git a/.prettierignore b/.prettierignore index f8f1e312..934dbfa2 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,4 +2,5 @@ /dist /node_modules /test/fixtures -CHANGELOG.md \ No newline at end of file +CHANGELOG.md +test/outputs/url/** diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index 4f14003f..00000000 --- a/.prettierrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { singleQuote: true }; diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a15594..d67beced 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,76 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [5.1.0](https://github.com/webpack-contrib/html-loader/compare/v5.0.0...v5.1.0) (2024-07-25) + + +### Features + +* added the `postprocessor` option ([#518](https://github.com/webpack-contrib/html-loader/issues/518)) ([536a204](https://github.com/webpack-contrib/html-loader/commit/536a204696c655b500c4805db8e857ac28aab7ed)) +* reduce runtime code ([61f9a69](https://github.com/webpack-contrib/html-loader/commit/61f9a69a60196abdc85afaa8658faf7736cf08a9)) +* support absolute URLs and DataURI ([#519](https://github.com/webpack-contrib/html-loader/issues/519)) ([cc34b06](https://github.com/webpack-contrib/html-loader/commit/cc34b068accee66d2f8ef10fb03ed90b866395db)) +* using template literals in code when it supported ([#520](https://github.com/webpack-contrib/html-loader/issues/520)) ([6fa80d5](https://github.com/webpack-contrib/html-loader/commit/6fa80d51fed22613c39ffb240a0e875c9151b5b6)) + +## [5.0.0](https://github.com/webpack-contrib/html-loader/compare/v4.2.0...v5.0.0) (2024-01-16) + + +### ⚠ BREAKING CHANGES + +* minimum supported Node.js version is `18.12.0` ([#504](https://github.com/webpack-contrib/html-loader/issues/504)) ([c82cfea](https://github.com/webpack-contrib/html-loader/commit/c82cfea0913aaf303d044c3a16f9b631dce5bc76)) + +## [4.2.0](https://github.com/webpack-contrib/html-loader/compare/v4.1.0...v4.2.0) (2022-09-22) + + +### Features + +* update html minifier ([#462](https://github.com/webpack-contrib/html-loader/issues/462)) ([27a6caf](https://github.com/webpack-contrib/html-loader/commit/27a6cafeabbfd506d7e2571ea5918dd8e8cb8d29)) + +## [4.1.0](https://github.com/webpack-contrib/html-loader/compare/v4.0.0...v4.1.0) (2022-07-11) + + +### Features + +* added the `scriptingEnabled` option ([#448](https://github.com/webpack-contrib/html-loader/issues/448)) ([6ed9f9c](https://github.com/webpack-contrib/html-loader/commit/6ed9f9c8df1e8ac2722bed01a9d28b660d64e744)) + +### [4.0.0](https://github.com/webpack-contrib/html-loader/compare/v3.1.0...v4.0.0) (2022-06-15) + +### ⚠ BREAKING CHANGES + +* minimum supported `Node.js` version is `14.15.0` +* update `parse5` to `7.0.0` + + +### Bug Fixes + +* handle text with `" to "<" + "script>" or "<" + "/script>". + code = code.replaceAll(/<(\/\?script)/g, (_, scriptTag) => + isTemplateLiteralSupported ? `\${"<${scriptTag}"}` : `<" + "${scriptTag}`, + ); + + code = `// Module\nvar code = ${code};\n`; + + if (needHelperImport) { + // TODO simplify in the next major release + const getURLRuntime = require.resolve("./runtime/getUrl.js"); + const context = loaderContext.context || loaderContext.rootContext; + const fileURLToHelper = + typeof loaderContext.utils !== "undefined" && + typeof loaderContext.utils.contextify === "function" + ? loaderContext.utils.contextify(context, getURLRuntime) + : contextify(context, getURLRuntime); + code = options.esModule + ? `import ${GET_SOURCE_FROM_IMPORT_NAME} from "${fileURLToHelper}";\n${code}` + : `var ${GET_SOURCE_FROM_IMPORT_NAME} = require("${fileURLToHelper}");\n${code}`; } - if (!value) { - throw new Error('Must be non-empty'); + return code; +} + +export function getExportCode(html, options) { + if (options.esModule) { + return "// Exports\nexport default code;"; } - return { value, startOffset }; + return "// Exports\nmodule.exports = code;"; } export function traverse(root, callback) { @@ -1289,13 +1348,32 @@ export function traverse(root, callback) { } if (res !== false && Array.isArray(childNodes) && childNodes.length >= 0) { - childNodes.forEach((child) => { + for (const child of childNodes) { visit(child, node); - }); + } } }; visit(root, null); } +export function supportTemplateLiteral(loaderContext) { + if (loaderContext.environment && loaderContext.environment.templateLiteral) { + return true; + } + + // TODO remove in the next major release + if ( + loaderContext._compilation && + loaderContext._compilation.options && + loaderContext._compilation.options.output && + loaderContext._compilation.options.output.environment && + loaderContext._compilation.options.output.environment.templateLiteral + ) { + return true; + } + + return false; +} + export const webpackIgnoreCommentRegexp = /webpackIgnore:(\s+)?(true|false)/; diff --git a/test/__snapshots__/esModule-option.test.js.snap b/test/__snapshots__/esModule-option.test.js.snap index 967d76f8..b7ae00fe 100644 --- a/test/__snapshots__/esModule-option.test.js.snap +++ b/test/__snapshots__/esModule-option.test.js.snap @@ -1,69 +1,493 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`'esModule' option should use a CommonJS export by default: errors 1`] = `Array []`; +exports[`'esModule' option should use a CommonJS export by default: errors 1`] = `[]`; exports[`'esModule' option should use a CommonJS export by default: module 1`] = ` "// Imports -import ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ from \\"../../src/runtime/getUrl.js\\"; -var ___HTML_LOADER_IMPORT_0___ = new URL(\\"./image.png\\", import.meta.url); -var ___HTML_LOADER_IMPORT_1___ = new URL(\\"/image.png\\", import.meta.url); -var ___HTML_LOADER_IMPORT_2___ = new URL(\\"aliasImg\\", import.meta.url); -var ___HTML_LOADER_IMPORT_3___ = new URL(\\"./script.file.js\\", import.meta.url); -var ___HTML_LOADER_IMPORT_4___ = new URL(\\"./icons.svg\\", import.meta.url); -var ___HTML_LOADER_IMPORT_5___ = new URL(\\"./image.png?foo=bar,baz\\", import.meta.url); -var ___HTML_LOADER_IMPORT_6___ = new URL(\\"./image.png?bar=baz,foo\\", import.meta.url); -var ___HTML_LOADER_IMPORT_7___ = new URL(\\"./example.ogg\\", import.meta.url); -var ___HTML_LOADER_IMPORT_8___ = new URL(\\"./example.pdf\\", import.meta.url); -var ___HTML_LOADER_IMPORT_9___ = new URL(\\"./example.vtt\\", import.meta.url); -var ___HTML_LOADER_IMPORT_10___ = new URL(\\"./style.file.css\\", import.meta.url); -var ___HTML_LOADER_IMPORT_11___ = new URL(\\"./image image.png\\", import.meta.url); -var ___HTML_LOADER_IMPORT_12___ = new URL(\\"./module.file.js\\", import.meta.url); -var ___HTML_LOADER_IMPORT_13___ = new URL(\\"./fallback.file.js\\", import.meta.url); -var ___HTML_LOADER_IMPORT_14___ = new URL(\\"aliasImageWithSpace\\", import.meta.url); -var ___HTML_LOADER_IMPORT_15___ = new URL(\\"./webpack.svg\\", import.meta.url); -var ___HTML_LOADER_IMPORT_16___ = new URL(\\"./pixel.png?url\\", import.meta.url); -var ___HTML_LOADER_IMPORT_17___ = new URL(\\"./site.webmanifest\\", import.meta.url); -var ___HTML_LOADER_IMPORT_18___ = new URL(\\"./browserconfig.xml\\", import.meta.url); -var ___HTML_LOADER_IMPORT_19___ = new URL(\\"./favicon.ico\\", import.meta.url); -var ___HTML_LOADER_IMPORT_20___ = new URL(\\"./sound.mp3\\", import.meta.url); -var ___HTML_LOADER_IMPORT_21___ = new URL(\\"./video.mp4\\", import.meta.url); -var ___HTML_LOADER_IMPORT_22___ = new URL(\\"./nested/image3.png\\", import.meta.url); -var ___HTML_LOADER_IMPORT_23___ = new URL(\\"/nested/image3.png\\", import.meta.url); +var ___HTML_LOADER_IMPORT_0___ = new URL("./image.png", import.meta.url); +var ___HTML_LOADER_IMPORT_1___ = new URL("/image.png", import.meta.url); +var ___HTML_LOADER_IMPORT_2___ = new URL("aliasImg", import.meta.url); +var ___HTML_LOADER_IMPORT_3___ = new URL("./script.file.js", import.meta.url); +var ___HTML_LOADER_IMPORT_4___ = new URL("./icons.svg", import.meta.url); +var ___HTML_LOADER_IMPORT_5___ = new URL("./image.png?foo=bar,baz", import.meta.url); +var ___HTML_LOADER_IMPORT_6___ = new URL("./image.png?bar=baz,foo", import.meta.url); +var ___HTML_LOADER_IMPORT_7___ = new URL("./example.ogg", import.meta.url); +var ___HTML_LOADER_IMPORT_8___ = new URL("./example.pdf", import.meta.url); +var ___HTML_LOADER_IMPORT_9___ = new URL("./example.vtt", import.meta.url); +var ___HTML_LOADER_IMPORT_10___ = new URL("./style.file.css", import.meta.url); +var ___HTML_LOADER_IMPORT_11___ = new URL("data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", import.meta.url); +var ___HTML_LOADER_IMPORT_12___ = new URL("./image image.png", import.meta.url); +var ___HTML_LOADER_IMPORT_13___ = new URL("./module.file.js", import.meta.url); +var ___HTML_LOADER_IMPORT_14___ = new URL("./fallback.file.js", import.meta.url); +var ___HTML_LOADER_IMPORT_15___ = new URL("aliasImageWithSpace", import.meta.url); +var ___HTML_LOADER_IMPORT_16___ = new URL("./webpack.svg", import.meta.url); +var ___HTML_LOADER_IMPORT_17___ = new URL("./pixel.png?url", import.meta.url); +var ___HTML_LOADER_IMPORT_18___ = new URL("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", import.meta.url); +var ___HTML_LOADER_IMPORT_19___ = new URL("./site.webmanifest", import.meta.url); +var ___HTML_LOADER_IMPORT_20___ = new URL("./browserconfig.xml", import.meta.url); +var ___HTML_LOADER_IMPORT_21___ = new URL("./favicon.ico", import.meta.url); +var ___HTML_LOADER_IMPORT_22___ = new URL("./sound.mp3", import.meta.url); +var ___HTML_LOADER_IMPORT_23___ = new URL("./video.mp4", import.meta.url); +var ___HTML_LOADER_IMPORT_24___ = new URL("./nested/image3.png", import.meta.url); +var ___HTML_LOADER_IMPORT_25___ = new URL("/nested/image3.png", import.meta.url); +var ___HTML_LOADER_IMPORT_26___ = new URL("./noscript.png", import.meta.url); +var ___HTML_LOADER_IMPORT_27___ = new URL("./πŸ˜€abc.png", import.meta.url); +import ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ from "../../src/runtime/getUrl.js"; // Module -var ___HTML_LOADER_REPLACEMENT_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___); -var ___HTML_LOADER_REPLACEMENT_1___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { maybeNeedQuotes: true }); -var ___HTML_LOADER_REPLACEMENT_2___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_1___); -var ___HTML_LOADER_REPLACEMENT_3___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_2___); -var ___HTML_LOADER_REPLACEMENT_4___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_3___); -var ___HTML_LOADER_REPLACEMENT_5___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_4___, { hash: \\"#icon-chevron-with-circle-up\\" }); -var ___HTML_LOADER_REPLACEMENT_6___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_5___); -var ___HTML_LOADER_REPLACEMENT_7___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_6___); -var ___HTML_LOADER_REPLACEMENT_8___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_7___); -var ___HTML_LOADER_REPLACEMENT_9___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_8___); -var ___HTML_LOADER_REPLACEMENT_10___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_9___); -var ___HTML_LOADER_REPLACEMENT_11___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_10___); -var ___HTML_LOADER_REPLACEMENT_12___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_11___); -var ___HTML_LOADER_REPLACEMENT_13___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_12___); -var ___HTML_LOADER_REPLACEMENT_14___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_13___); -var ___HTML_LOADER_REPLACEMENT_15___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_14___, { maybeNeedQuotes: true }); -var ___HTML_LOADER_REPLACEMENT_16___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_14___); -var ___HTML_LOADER_REPLACEMENT_17___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#hash\\" }); -var ___HTML_LOADER_REPLACEMENT_18___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#hash\\", maybeNeedQuotes: true }); -var ___HTML_LOADER_REPLACEMENT_19___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#\\", maybeNeedQuotes: true }); -var ___HTML_LOADER_REPLACEMENT_20___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#foo\\" }); -var ___HTML_LOADER_REPLACEMENT_21___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#bar\\" }); -var ___HTML_LOADER_REPLACEMENT_22___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#baz\\" }); -var ___HTML_LOADER_REPLACEMENT_23___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_14___, { hash: \\"#hash\\", maybeNeedQuotes: true }); -var ___HTML_LOADER_REPLACEMENT_24___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_15___); -var ___HTML_LOADER_REPLACEMENT_25___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_16___); -var ___HTML_LOADER_REPLACEMENT_26___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_17___); -var ___HTML_LOADER_REPLACEMENT_27___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_18___); -var ___HTML_LOADER_REPLACEMENT_28___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_19___); -var ___HTML_LOADER_REPLACEMENT_29___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_20___); -var ___HTML_LOADER_REPLACEMENT_30___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_21___); -var ___HTML_LOADER_REPLACEMENT_31___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_22___); -var ___HTML_LOADER_REPLACEMENT_32___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_23___); -var code = \\"\\\\n\\\\n

My First Heading

\\\\n

My first paragraph.

\\\\n

An Unordered HTML List

\\\\n\\\\n\\\\n\\\\n

An Ordered HTML List

\\\\n\\\\n
    \\\\n
  1. Coffee
  2. \\\\n
  3. Tea
  4. \\\\n
  5. Milk
  6. \\\\n
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n
Foo
\\\\n\\\\n\\\\n
BAR
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\n\\\\n \\\\n \\\\n \\\\\\"Flowers\\\\\\"\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\\\"Smiley\\\\n\\\\n
\\\\n First name:
\\\\n \\\\n
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\nT ex t \\\\n\\\\n
\\\\n\\\\n]]>\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\nlink text\\\\n\\\\nCall me\\\\n\\\\n-->\\\\n-->\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n
\\\\n
\\\\n\\\\n<div id = "character">\\\\n© 2007\\\\nor\\\\n© 2007\\\\n\\\\n
\\\\n\\\\n\\\\\\"Red\\\\n
\\\\n Written by Jon Doe.
\\\\n Visit us at:
\\\\n Example.com
\\\\n Box 564, Disneyland
\\\\n USA\\\\n
\\\\nlink\\\\nStart Chat\\\\nStart Chat\\\\nStart Chat\\\\n\\\\n\\\\n\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\n\\\\\\"Elva\\\\n\\\\\\"Test\\\\\\"\\\\n\\\\n\\\\n\\\\n Test \\\\n\\\\ntest\\\\ntest\\\\ntest\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n

Text

\\\\n

Text

\\\\n

Text

\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\\\"Elva\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\\\"Elva\\\\n\\\\\\"test\\\\\\"/\\\\n\\\\\\"test\\\\\\"\\\\n\\\\\\"test\\\\\\"\\\\n\\\\\\"test\\\\\\"/\\\\n\\\\\\"test\\\\\\"/\\\\n\\\\n\\\\n\\\\\\"Elva\\\\n\\\\n\\\\n\\\\n\\\\n \\\\n\\\\n\\\\n\\\\n \\\\n\\\\n\\\\n\\\\n \\\\n\\\\n\\\\n\\\\n \\\\n\\\\n\\\\nfoo bar\\\\n\\\\nText\\\\nText\\\\n\\\\n\\\\n\\\\n
\\\\n\\\\nVisit our HTML tutorial\\\\nVisit our HTML tutorial\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n
text
\\\\n
text
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\\\"\\\\\\"\\\\n\\\\n\\\\\\"\\\\\\"\\\\n\\\\n\\\\\\"multi\\\\nline\\\\nalt\\\\\\"\\\\n\\\\n\\\\\\"Red\\\\n\\\\n\\\\\\" alt=\\\\\\"<%= name %>\\\\\\" src=\\\\\\"<%= imgsrc %>\\\\\\" />\\\\n\\\\n\\\\n \\\\n\\\\n\\\\n \\\\n\\\\n\\\\n \\\\n\\\\n\\\\n \\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n
\\\\n \\\\n
\\"; +var code = \` + +

My First Heading

+

My first paragraph.

+

An Unordered HTML List

+ +
    +
  • Coffee
  • +
  • Tea
  • +
  • Milk
  • +
+ +

An Ordered HTML List

+ +
    +
  1. Coffee
  2. +
  3. Tea
  4. +
  5. Milk
  6. +
+ + + + + +
Foo
+ + +
BAR
+ + + + + + + + + + + + + + + + + + + + + + + + + + +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy + + + + + Flowers + + + + + + + + +Smiley face + +
+ First name:
+ +
+ + + + + + + + + + + + + +T ex t + +
+ +]]> + + + + + + + + + + + + + + + + + + + + + + + + + +Call me + +--> +--> + + + + + +
+
+ +<div id = "character"> +© 2007 +or +© 2007 + +
+ +Red dot +
+ Written by Jon Doe.
+ Visit us at:
+ Example.com
+ Box 564, Disneyland
+ USA +
+link +Start Chat +Start Chat +Start Chat + + + +Elva dressed as a fairy +Elva dressed as a fairy + +Elva dressed as a fairy +Test + + + + Test + +test +test +test + + + + + +

Text

+

Text

+

Text

+ + + + + + + + + + + + + + + + + + + + +Elva dressed as a fairy + + + + + + + + + + + +Elva dressed as a fairy +test +test +test +test +test + + +Elva dressed as a fairy + + + + + + + + + + + + + + + + + + + +foo bar + +Text +Text + + + +
+ +Visit our HTML tutorial +Visit our HTML tutorial + + + + + +
text
+
text
+ + + + + + + + + +multi
+line
+alt + +Red dot + +<%= name %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +Smiley face +Smiley face +Elva dressed as a fairy +Elva dressed as a fairy +\`; // Exports export default code;" `; @@ -89,7 +513,7 @@ exports[`'esModule' option should use a CommonJS export by default: result 1`] =
  • Milk
  • - + @@ -98,144 +522,144 @@ exports[`'esModule' option should use a CommonJS export by default: result 1`] =
    BAR
    - + - - - - - - - - - - - + + + + + + + + + + + - + - - + + - + - + -\\"Elva -\\"Elva -\\"Elva -\\"Elva -\\"Elva -\\"Elva -\\"Elva -\\"Elva -\\"Elva -\\"Elva -\\"Elva -\\"Elva -Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +Elva dressed as a fairy +\\"Elva +" src="replaced_file_protocol_/webpack/public/path/image-7bc91c245a8a10a4.png" alt="Elva dressed as a fairy"> - - - \\"Flowers\\" + + + Flowers -