GoogleChromeLabs / worker-plugin

👩‍🏭 Adds native Web Worker bundling support to Webpack.
https://npm.im/worker-plugin
Apache License 2.0
1.91k stars 79 forks source link

Warnings in terminal when using with vue cli (eslint + prettier configured) #100

Closed Cornpop456 closed 3 years ago

Cornpop456 commented 3 years ago

A problem ocurred only in worker file, prettier is configured to auto format all js file on save

This is simple example which i play with, everything is fine except this warnings and the fact that hmr does not triggered by changes in worker file (but it seems to be a normal behavior if i am not wrong)

self.arr = [];
self.addEventListener('connect', (ev) => {
  let port = ev.ports[0];

  console.log(self.arr);

  port.postMessage('hello i am  cool shared worker!');

  port.addEventListener('message', function (e) {
    self.arr.push(2);
    console.log(...self.arr);
    port.postMessage(e.data);
  });
  port.start();
});

worker js - cryptonomicon - Visual Studio Code 2021-03-30 01 57 24

I did not change anything in any configs, generated by vue-cli, babel, eslint, etc

Only added this plugin to support workers

const WorkerPlugin = require('worker-plugin');
module.exports = {
  configureWebpack: {
    plugins: [new WorkerPlugin({ sharedWorker: true })],
  },
};
luffs commented 2 years ago

I had a similar issue with Vue + eslint. Except my eslint config treated deviation from the code style as errors, causing the build to fail randomly about half of the time.

Syntax Error: ModuleError: Module Error (from ./node_modules/thread-loader/dist/cjs.js):
  1:27  error  Extra semicolon                                semi
  1:28  error  Newline required at end of file but not found  eol-last

I found a workaround in adding a proxy file and disabling eslint by adding / eslint-disable / to the beginning of the file.

proxy-shared-worker.js

/* eslint-disable */
import './real-shared-worker.js'