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

Commit

Permalink
chore(deps): update (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Dec 2, 2020
1 parent 15cf407 commit 08fa5c5
Show file tree
Hide file tree
Showing 36 changed files with 2,478 additions and 3,242 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['@webpack-contrib/eslint-config-webpack', 'prettier'],
extends: ["@webpack-contrib/eslint-config-webpack", "prettier"],
};
1 change: 0 additions & 1 deletion .prettierrc.js

This file was deleted.

98 changes: 49 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $ npm install worker-loader --save-dev
**App.js**

```js
import Worker from 'worker-loader!./Worker.js';
import Worker from "worker-loader!./Worker.js";
```

### Config
Expand All @@ -42,7 +42,7 @@ module.exports = {
rules: [
{
test: /\.worker\.js$/,
use: { loader: 'worker-loader' },
use: { loader: "worker-loader" },
},
],
},
Expand All @@ -52,14 +52,14 @@ module.exports = {
**App.js**

```js
import Worker from './file.worker.js';
import Worker from "./file.worker.js";

const worker = new Worker();

worker.postMessage({ a: 1 });
worker.onmessage = function (event) {};

worker.addEventListener('message', function (event) {});
worker.addEventListener("message", function (event) {});
```

And run `webpack` via your preferred method.
Expand Down Expand Up @@ -94,9 +94,9 @@ module.exports = {
rules: [
{
test: /\.worker\.(c|m)?js$/i,
loader: 'worker-loader',
loader: "worker-loader",
options: {
worker: 'SharedWorker',
worker: "SharedWorker",
},
},
],
Expand All @@ -116,14 +116,14 @@ module.exports = {
rules: [
{
test: /\.worker\.(c|m)?js$/i,
loader: 'worker-loader',
loader: "worker-loader",
options: {
worker: {
type: 'SharedWorker',
type: "SharedWorker",
options: {
type: 'classic',
credentials: 'omit',
name: 'my-custom-worker-name',
type: "classic",
credentials: "omit",
name: "my-custom-worker-name",
},
},
},
Expand Down Expand Up @@ -151,9 +151,9 @@ module.exports = {
rules: [
{
test: /\.worker\.(c|m)?js$/i,
loader: 'worker-loader',
loader: "worker-loader",
options: {
publicPath: '/scripts/workers/',
publicPath: "/scripts/workers/",
},
},
],
Expand All @@ -171,7 +171,7 @@ module.exports = {
rules: [
{
test: /\.worker\.(c|m)?js$/i,
loader: 'worker-loader',
loader: "worker-loader",
options: {
publicPath: (pathData, assetInfo) => {
return `/scripts/${pathData.hash}/workers/`;
Expand Down Expand Up @@ -200,9 +200,9 @@ module.exports = {
rules: [
{
test: /\.worker\.(c|m)?js$/i,
loader: 'worker-loader',
loader: "worker-loader",
options: {
filename: '[name].[contenthash].worker.js',
filename: "[name].[contenthash].worker.js",
},
},
],
Expand All @@ -220,16 +220,16 @@ module.exports = {
rules: [
{
test: /\.worker\.(c|m)?js$/i,
loader: 'worker-loader',
loader: "worker-loader",
options: {
filename: (pathData) => {
if (
/\.worker\.(c|m)?js$/i.test(pathData.chunk.entryModule.resource)
) {
return '[name].custom.worker.js';
return "[name].custom.worker.js";
}

return '[name].js';
return "[name].js";
},
},
},
Expand All @@ -253,9 +253,9 @@ module.exports = {
rules: [
{
test: /\.worker\.(c|m)?js$/i,
loader: 'worker-loader',
loader: "worker-loader",
options: {
chunkFilename: '[id].[contenthash].worker.js',
chunkFilename: "[id].[contenthash].worker.js",
},
},
],
Expand All @@ -280,9 +280,9 @@ module.exports = {
rules: [
{
test: /\.worker\.(c|m)?js$/i,
loader: 'worker-loader',
loader: "worker-loader",
options: {
inline: 'fallback',
inline: "fallback",
},
},
],
Expand All @@ -307,7 +307,7 @@ module.exports = {
rules: [
{
test: /\.worker\.(c|m)?js$/i,
loader: 'worker-loader',
loader: "worker-loader",
options: {
esModule: false,
},
Expand All @@ -326,26 +326,26 @@ The worker file can import dependencies just like any other file:
**index.js**

```js
import Worker from './my.worker.js';
import Worker from "./my.worker.js";

var worker = new Worker();

var result;

worker.onmessage = function (event) {
if (!result) {
result = document.createElement('div');
result.setAttribute('id', 'result');
result = document.createElement("div");
result.setAttribute("id", "result");

document.body.append(result);
}

result.innerText = JSON.stringify(event.data);
};

const button = document.getElementById('button');
const button = document.getElementById("button");

button.addEventListener('click', function () {
button.addEventListener("click", function () {
worker.postMessage({ postMessage: true });
});
```
Expand All @@ -370,7 +370,7 @@ module.exports = {
rules: [
{
test: /\.worker\.(c|m)?js$/i,
loader: 'worker-loader',
loader: "worker-loader",
options: {
esModule: false,
},
Expand All @@ -387,26 +387,26 @@ You can even use ES6+ features if you have the [`babel-loader`](https://github.c
**index.js**

```js
import Worker from './my.worker.js';
import Worker from "./my.worker.js";

const worker = new Worker();

let result;

worker.onmessage = (event) => {
if (!result) {
result = document.createElement('div');
result.setAttribute('id', 'result');
result = document.createElement("div");
result.setAttribute("id", "result");

document.body.append(result);
}

result.innerText = JSON.stringify(event.data);
};

const button = document.getElementById('button');
const button = document.getElementById("button");

button.addEventListener('click', () => {
button.addEventListener("click", () => {
worker.postMessage({ postMessage: true });
});
```
Expand All @@ -433,12 +433,12 @@ module.exports = {
test: /\.worker\.(c|m)?js$/i,
use: [
{
loader: 'worker-loader',
loader: "worker-loader",
},
{
loader: 'babel-loader',
loader: "babel-loader",
options: {
presets: ['@babel/preset-env'],
presets: ["@babel/preset-env"],
},
},
],
Expand All @@ -455,7 +455,7 @@ To integrate with TypeScript, you will need to define a custom module for the ex
**typings/worker-loader.d.ts**

```typescript
declare module 'worker-loader!*' {
declare module "worker-loader!*" {
// You need to change `Worker`, if you specified a different value for the `workerType` option
class WebpackWorker extends Worker {
constructor();
Expand All @@ -473,23 +473,23 @@ declare module 'worker-loader!*' {
const ctx: Worker = self as any;

// Post data to parent thread
ctx.postMessage({ foo: 'foo' });
ctx.postMessage({ foo: "foo" });

// Respond to message from parent thread
ctx.addEventListener('message', (event) => console.log(event));
ctx.addEventListener("message", (event) => console.log(event));
```

**index.ts**

```typescript
import Worker from 'worker-loader!./Worker';
import Worker from "worker-loader!./Worker";

const worker = new Worker();

worker.postMessage({ a: 1 });
worker.onmessage = (event) => {};

worker.addEventListener('message', (event) => {});
worker.addEventListener("message", (event) => {});
```

### Cross-Origin Policy
Expand All @@ -505,7 +505,7 @@ Firstly, you can inline the worker as a blob instead of downloading it as an ext
**App.js**

```js
import Worker from './file.worker.js';
import Worker from "./file.worker.js";
```

**webpack.config.js**
Expand All @@ -515,8 +515,8 @@ module.exports = {
module: {
rules: [
{
loader: 'worker-loader',
options: { inline: 'fallback' },
loader: "worker-loader",
options: { inline: "fallback" },
},
],
},
Expand All @@ -529,7 +529,7 @@ Secondly, you may override the base download URL for your worker script via the

```js
// This will cause the worker to be downloaded from `/workers/file.worker.js`
import Worker from './file.worker.js';
import Worker from "./file.worker.js";
```

**webpack.config.js**
Expand All @@ -539,8 +539,8 @@ module.exports = {
module: {
rules: [
{
loader: 'worker-loader',
options: { publicPath: '/workers/' },
loader: "worker-loader",
options: { publicPath: "/workers/" },
},
],
},
Expand Down
10 changes: 5 additions & 5 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ module.exports = (api) => {
return {
presets: [
[
'@babel/preset-env',
"@babel/preset-env",
{
targets: {
node: '10.13.0',
node: "10.13.0",
},
},
],
],
overrides: [
{
test: './src/runtime',
test: "./src/runtime",
presets: [
[
'@babel/preset-env',
"@babel/preset-env",
{
targets: {
node: '0.12',
node: "0.12",
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
extends: ["@commitlint/config-conventional"],
};
4 changes: 2 additions & 2 deletions globalSetupTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import path from "path";

// eslint-disable-next-line import/no-extraneous-dependencies
import del from 'del';
import del from "del";

async function setup() {
await del(path.resolve(__dirname, `./test/outputs`));
Expand Down
4 changes: 2 additions & 2 deletions husky.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
hooks: {
'pre-commit': 'lint-staged',
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
},
};
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
testEnvironment: 'node',
globalSetup: '<rootDir>/globalSetupTest.js',
setupFilesAfterEnv: ['<rootDir>/setupTest.js'],
testEnvironment: "node",
globalSetup: "<rootDir>/globalSetupTest.js",
setupFilesAfterEnv: ["<rootDir>/setupTest.js"],
};
4 changes: 2 additions & 2 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
'*.js': ['prettier --write', 'eslint --fix'],
'*.{json,md,yml,css,ts}': ['prettier --write'],
"*.js": ["eslint --fix", "prettier --write"],
"*.{json,md,yml,css,ts}": ["prettier --write"],
};
Loading

0 comments on commit 08fa5c5

Please sign in to comment.