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

Vue2 + Webpack not bundling? #109

Closed Sjoerd82 closed 2 years ago

Sjoerd82 commented 2 years ago

I get the following error:

"Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec."

This leads me to suspect that the .js worker file isn't added (returns a 404 perhaps, hence the text/html MIME error??)

vue.config.js

const WorkerPlugin = require('worker-plugin')
module.exports = {
    pwa: {
        workboxPluginMode: 'InjectManifest',
        workboxOptions: {
            swSrc: 'public/service-worker.js',
            exclude: [
                /_redirects/,
                /\.map$/, 
                /manifest\.json$/ 
            ],
        },
        start_url: '/.',
        display: 'standalone',
        background_color: '#000000',
        themeColor: '#000000',
        msTileColor: '#000000',
        backgroundColor: '#000000',
    },
    configureWebpack: {
        output: {
          globalObject: "this",
        },
        plugins: [
            new WorkerPlugin({
                globalObject: "self",
                preserveTypeModule: true,
            })
        ]
    }
}

App.vue const myWorker = new Worker('@/worker.js', {type:'module'})

The worker.js file is located in the root folder, same as where the App.vue is. I've seen similar issue being reported but without any solutions that work for this case.

Sjoerd82 commented 2 years ago

hmm, not sure what I changed, but it's now working........

Sjoerd82 commented 2 years ago

turned out that hard restarting the development server fixed the issue...