Skip to content
This repository was archived by the owner on Sep 9, 2021. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: webpack-contrib/worker-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.0.2
Choose a base ref
...
head repository: webpack-contrib/worker-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.0.3
Choose a head ref
  • 4 commits
  • 18 files changed
  • 3 contributors

Commits on Sep 21, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6c8f8ef View commit details

Commits on Sep 22, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0d4624c View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    eef2757 View commit details
  3. chore(release): 3.0.3

    alexander-akait committed Sep 22, 2020
    Copy the full SHA
    2974de4 View commit details
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,14 @@

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.

### [3.0.3](https://github.com/webpack-contrib/worker-loader/compare/v3.0.2...v3.0.3) (2020-09-22)


### Bug Fixes

* remove unnecessary webpack sourceURL ([#289](https://github.com/webpack-contrib/worker-loader/issues/289)) ([eef2757](https://github.com/webpack-contrib/worker-loader/commit/eef27574160f519c344dfa5fd981b7ac561a8939))
* compatibility with eval source maps ([#286](https://github.com/webpack-contrib/worker-loader/issues/286)) ([0d4624c](https://github.com/webpack-contrib/worker-loader/commit/0d4624c178c426aa97e5175a5f321e43de482c2b))

### [3.0.2](https://github.com/webpack-contrib/worker-loader/compare/v3.0.1...v3.0.2) (2020-08-22)


16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -66,14 +66,14 @@ And run `webpack` via your preferred method.

## Options

| Name | Type | Default | Description |
| :-----------------------------------: | :--------------------------: | :-----------------------------: | :-------------------------------------------------------------------------------- |
| **[`worker`](#worker)** | `{String\|Object}` | `Worker` | Allows to set web worker constructor name and options |
| **[`publicPath`](#publicpath)** | `{String\|Function}` | based on `output.publicPath` | specifies the public URL address of the output files when referenced in a browser |
| **[`filename`](#filename)** | `{String\|Function}` | based on `output.filename` | The filename of entry chunks for web workers |
| **[`chunkFilename`](#chunkfilename)** | `{String}` | based on `output.chunkFilename` | The filename of non-entry chunks for web workers |
| **[`inline`](#inline)** | `'no-fallback'\|'fallback'` | `undefined` | Allow to inline the worker as a `BLOB` |
| **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax |
| Name | Type | Default | Description |
| :-----------------------------------: | :-------------------------: | :-----------------------------: | :-------------------------------------------------------------------------------- |
| **[`worker`](#worker)** | `{String\|Object}` | `Worker` | Allows to set web worker constructor name and options |
| **[`publicPath`](#publicpath)** | `{String\|Function}` | based on `output.publicPath` | specifies the public URL address of the output files when referenced in a browser |
| **[`filename`](#filename)** | `{String\|Function}` | based on `output.filename` | The filename of entry chunks for web workers |
| **[`chunkFilename`](#chunkfilename)** | `{String}` | based on `output.chunkFilename` | The filename of non-entry chunks for web workers |
| **[`inline`](#inline)** | `'no-fallback'\|'fallback'` | `undefined` | Allow to inline the worker as a `BLOB` |
| **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax |

### `worker`

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "worker-loader",
"version": "3.0.2",
"version": "3.0.3",
"description": "worker loader module for webpack",
"license": "MIT",
"repository": "webpack-contrib/worker-loader",
2 changes: 1 addition & 1 deletion src/runtime/inline.js
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ module.exports = (content, workerConstructor, workerOptions, url) => {

blob = blob.getBlob();
}

const URL = window.URL || window.webkitURL;
const objectURL = URL.createObjectURL(blob);
const worker = new window[workerConstructor](objectURL, workerOptions);
9 changes: 8 additions & 1 deletion src/supportWebpack4.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { workerGenerator, sourceMappingURLRegex } from './utils';
import {
workerGenerator,
sourceMappingURLRegex,
sourceURLWebpackRegex,
} from './utils';

export default function runAsChild(
loaderContext,
@@ -30,6 +34,9 @@ export default function runAsChild(

// Remove `/* sourceMappingURL=url */` comment
workerSource = workerSource.replace(sourceMappingURLRegex, '');

// Remove `//# sourceURL=webpack-internal` comment
workerSource = workerSource.replace(sourceURLWebpackRegex, '');
}

const workerCode = workerGenerator(
9 changes: 8 additions & 1 deletion src/supportWebpack5.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { workerGenerator, sourceMappingURLRegex } from './utils';
import {
workerGenerator,
sourceMappingURLRegex,
sourceURLWebpackRegex,
} from './utils';

export default function runAsChild(
loaderContext,
@@ -45,6 +49,9 @@ export default function runAsChild(
if (options.inline === 'no-fallback') {
// Remove `/* sourceMappingURL=url */` comment
workerSource = workerSource.replace(sourceMappingURLRegex, '');

// Remove `//# sourceURL=webpack-internal` comment
workerSource = workerSource.replace(sourceURLWebpackRegex, '');
}

const workerCode = workerGenerator(
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ ${
}

// Matches only the last occurrence of sourceMappingURL
const innerRegex = /\s*[#@]\s*sourceMappingURL\s*=\s*([^\s'"]*)\s*/;
const innerRegex = /\s*[#@]\s*sourceMappingURL\s*=\s*(.*?(?=[\s'"]|\\n|\*\/|$)(?:\\n)?)\s*/;

/* eslint-disable prefer-template */
const sourceMappingURLRegex = RegExp(
@@ -106,6 +106,10 @@ const sourceMappingURLRegex = RegExp(
')' +
'\\s*'
);

const sourceURLWebpackRegex = RegExp(
'\\/\\/#\\ssourceURL=webpack-internal:\\/\\/\\/(.*?)\\\\n'
);
/* eslint-enable prefer-template */

export {
@@ -114,4 +118,5 @@ export {
getExternalsType,
workerGenerator,
sourceMappingURLRegex,
sourceURLWebpackRegex,
};
15 changes: 15 additions & 0 deletions test/__snapshots__/chunkFilename-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"name" option should chunkFilename suffix be inserted before query parameters: errors 1`] = `Array []`;

exports[`"name" option should chunkFilename suffix be inserted before query parameters: module 1`] = `
"export default function() {
return new Worker(__webpack_public_path__ + \\"worker.worker.js\\");
}
"
`;

exports[`"name" option should chunkFilename suffix be inserted before query parameters: result 1`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`;

exports[`"name" option should chunkFilename suffix be inserted before query parameters: result 2`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`;

exports[`"name" option should chunkFilename suffix be inserted before query parameters: warnings 1`] = `Array []`;

exports[`"name" option should work ("string"): errors 1`] = `Array []`;

exports[`"name" option should work ("string"): module 1`] = `
6 changes: 6 additions & 0 deletions test/__snapshots__/inline-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -55,6 +55,12 @@ exports[`"inline" option should work with "no-fallback" value and "esModule" wit

exports[`"inline" option should work with "no-fallback" value and "esModule" with "true" value: warnings 1`] = `Array []`;

exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("eval-source-map" value): errors 1`] = `Array []`;

exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("eval-source-map" value): result 1`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`;

exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("eval-source-map" value): warnings 1`] = `Array []`;

exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("source-map" value): errors 1`] = `Array []`;

exports[`"inline" option should work with "no-fallback" value and the "devtool" option ("source-map" value): errors 2`] = `Array []`;
55 changes: 55 additions & 0 deletions test/__snapshots__/sourceMapperRegexp.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`source-map-loader should work with "
with SourceMap
// #sourceMappingURL = /sample-source-map.map
// comment
" url: result 1`] = `
"
with SourceMap
REPLASED// comment
"
`;

exports[`source-map-loader should work with " // # sourceMappingURL = absolute-sourceRoot-source-map.map " url: result 1`] = `" REPLASED"`;

exports[`source-map-loader should work with " // #sourceMappingURL=absolute-sourceRoot-source-map.map" url: result 1`] = `" REPLASED"`;

exports[`source-map-loader should work with "/* #sourceMappingURL=absolute-sourceRoot-source-map.map */" url: result 1`] = `"REPLASED"`;

exports[`source-map-loader should work with "/*#sourceMappingURL=absolute-sourceRoot-source-map.map*/" url: result 1`] = `"REPLASED"`;

exports[`source-map-loader should work with "// #sourceMappingURL = //sampledomain.com/external-source-map2.map" url: result 1`] = `"REPLASED"`;

exports[`source-map-loader should work with "// #sourceMappingURL = http://sampledomain.com/external-source-map2.map" url: result 1`] = `"REPLASED"`;

exports[`source-map-loader should work with "// @sourceMappingURL=data:application/source-map;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lLXNvdXJjZS1tYXAuanMiLCJzb3VyY2VzIjpbImlubGluZS1zb3VyY2UtbWFwLnR4dCJdLCJzb3VyY2VzQ29udGVudCI6WyJ3aXRoIFNvdXJjZU1hcCJdLCJtYXBwaW5ncyI6IkFBQUEifQ==" url: result 1`] = `"REPLASED"`;

exports[`source-map-loader should work with "//#sourceMappingURL=absolute-sourceRoot-source-map.map" url: result 1`] = `"REPLASED"`;

exports[`source-map-loader should work with "//@sourceMappingURL=absolute-sourceRoot-source-map.map" url: result 1`] = `"REPLASED"`;

exports[`source-map-loader should work with "onmessage = function(event) {
const workerResult = event.data;
workerResult.onmessage = true;
postMessage(workerResult);
};
//# sourceURL=[module]
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vLi9iYXNpYy93b3JrZXIuanM/OGFiZiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQUNBOztBQUVBOztBQUVBO0FBQ0EiLCJmaWxlIjoiLi9iYXNpYy93b3JrZXIuanMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJvbm1lc3NhZ2UgPSBmdW5jdGlvbihldmVudCkge1xuICBjb25zdCB3b3JrZXJSZXN1bHQgPSBldmVudC5kYXRhO1xuXG4gIHdvcmtlclJlc3VsdC5vbm1lc3NhZ2UgPSB0cnVlO1xuXG4gIHBvc3RNZXNzYWdlKHdvcmtlclJlc3VsdCk7XG59O1xuIl0sInNvdXJjZVJvb3QiOiIifQ==
//# sourceURL=webpack-internal:///./basic/worker.js
" url: result 1`] = `
"onmessage = function(event) {
const workerResult = event.data;
workerResult.onmessage = true;
postMessage(workerResult);
};
//# sourceURL=[module]
REPLASED//# sourceURL=webpack-internal:///./basic/worker.js
"
`;
49 changes: 49 additions & 0 deletions test/chunkFilename-option.test.js
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ describe('"name" option', () => {
output: {
path: path.resolve(__dirname, './outputs', `test_${nanoid()}`),
filename: '[name].js',
publicPath: '',
},
module: {
rules: [
@@ -72,6 +73,7 @@ describe('"name" option', () => {
path: path.resolve(__dirname, './outputs', `test_${nanoid()}`),
filename: '[name].js',
chunkFilename: '[name].chunk.js',
publicPath: '',
},
module: {
rules: [
@@ -97,4 +99,51 @@ describe('"name" option', () => {
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('should chunkFilename suffix be inserted before query parameters', async () => {
const nanoid = customAlphabet('1234567890abcdef', 10);
const compiler = getCompiler(
'./chunks/entry.js',
{},
{
output: {
path: path.resolve(__dirname, './outputs', `test_${nanoid()}`),
filename: '[name].js',
chunkFilename: '[name].chunk.js?foo=bar&baz=bar',
publicPath: '',
},
module: {
rules: [
{
test: /worker\.js$/i,
rules: [
{
loader: path.resolve(__dirname, '../src'),
},
],
},
],
},
}
);
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);

let hasChankName = false;

Object.keys(stats.compilation.assets).forEach((asset) => {
if (asset.endsWith('chunk.worker.js?foo=bar&baz=bar')) {
hasChankName = true;
}
});

expect(hasChankName).toBe(true);
expect(result).toMatchSnapshot('result');
expect(getModuleSource('./chunks/worker.js', stats)).toMatchSnapshot(
'module'
);
expect(result).toMatchSnapshot('result');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});
});
3 changes: 3 additions & 0 deletions test/filename-options.test.js
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ describe('"filename" option', () => {
output: {
path: path.resolve(__dirname, './outputs', `test_${nanoid()}`),
chunkFilename: '[name].chunk.js',
publicPath: '',
},
module: {
rules: [
@@ -87,6 +88,7 @@ describe('"filename" option', () => {
path: path.resolve(__dirname, './outputs', `test_${nanoid()}`),
filename: '[name].custom.js',
chunkFilename: '[name].chunk.js',
publicPath: '',
},
module: {
rules: [
@@ -128,6 +130,7 @@ describe('"filename" option', () => {

return '[name].js';
},
publicPath: '',
},
module: {
rules: [
1 change: 1 addition & 0 deletions test/helpers/getCompiler.js
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ export default (fixture, loaderOptions = {}, config = {}) => {
path: path.resolve(__dirname, '../outputs', `test_${nanoid()}`),
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js',
publicPath: '',
},
module: {
rules: [
4 changes: 3 additions & 1 deletion test/helpers/getResultFromBrowser.js
Original file line number Diff line number Diff line change
@@ -20,7 +20,9 @@ export default async function getResultFromBrowser(stats) {
);

for (const asset of assets) {
const [route] = asset;
let [route] = asset;
[route] = route.split('?');

const existsAt = path.resolve(stats.compilation.outputOptions.path, route);

if (route === 'index.html') {
30 changes: 30 additions & 0 deletions test/inline-option.test.js
Original file line number Diff line number Diff line change
@@ -62,6 +62,36 @@ describe('"inline" option', () => {
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('should work with "no-fallback" value and the "devtool" option ("eval-source-map" value)', async () => {
const compiler = getCompiler(
'./basic/entry.js',
{ inline: 'no-fallback' },
{ devtool: 'eval-source-map' }
);
const stats = await compile(compiler);
const result = await getResultFromBrowser(stats);
const moduleSource = getModuleSource('./basic/worker.js', stats);
const sourceUrlInternalIndex = moduleSource.indexOf(
'sourceURL=webpack-internal:///./basic/worker.js'
);

expect(moduleSource.indexOf('inline.js') > 0).toBe(true);
expect(
moduleSource.indexOf('__webpack_public_path__ + "test.worker.js"') === -1
).toBe(true);
expect(
moduleSource.indexOf(
'sourceMappingURL=data:application/json;charset=utf-8;base64,'
) === -1
).toBe(true);
expect(sourceUrlInternalIndex === -1).toBe(true);
expect(stats.compilation.assets['test.worker.js']).toBeUndefined();
expect(stats.compilation.assets['test.worker.js.map']).toBeUndefined();
expect(result).toMatchSnapshot('result');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('should work with "no-fallback" value and the "devtool" option ("source-map" value)', async () => {
const compiler = getCompiler(
'./basic/entry.js',
1 change: 1 addition & 0 deletions test/publicPath.test.js
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@ describe('"publicPath" option', () => {
path: path.resolve(__dirname, './outputs', `test_${nanoid()}`),
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js',
publicPath: '',
},
}
);
Loading