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

[FIXED] Options (name/publicPath) doesn't work with Typescript and Webpack 3 config file #123

Closed
Melmoth-the-Wanderer opened this issue Feb 6, 2018 · 1 comment

Comments

@Melmoth-the-Wanderer
Copy link

Melmoth-the-Wanderer commented Feb 6, 2018

I'm Using Webpack 3.10.0, Typescript 2.6.2, worker-loader 1.1.0.
webpack.config

module: {
            rules: [
                { ... } ,
                {
                    test: /\.worker\.js$/,
                    use: { 
                        loader: 'worker-loader',
                        options: { 
                            name: 'webWorker.[hash].worker.js',
                            publicPath: '/scripts/' 
                        }
                    }
                }
            ]
        }

App.ts:

import Worker = require("worker-loader!./Worker");

Worker.ts:

const ctx: Worker = self as any;
// Post data to parent thread
ctx.postMessage({ foo: "foo" });
// Respond to message from parent thread
ctx.addEventListener("message", (event) => console.log(event));

It compiles, but the file is outputted under f88912265db2b5d37cdb.worker.js filename, and the path doesn't include /scripts/ part.

I've tried to change import statement to include options as params as follows (based on #117 )
App.ts:

import Worker = require("worker-loader?name=scripts/worker.js!./Worker");

Above import throws following error:
Cannot find module 'worker-loader?name=scripts/worker.js!./Worker'. but after all it compiles properly and javascript works, hence I'm not allowed to leave error message in console.

I'd like to make options section working with Typescript OR get rid of "Cannot ind module" ERROR.

@Melmoth-the-Wanderer
Copy link
Author

Melmoth-the-Wanderer commented Feb 6, 2018

Fixed
For anyone reading this, #117 fixes the problem.
Just make sure to have your definition file up to date with import statement:

App.ts

import Worker = require("worker-loader?publicPath=scripts/&name=worker.js!./Worker");

workers/index.d.ts

declare module "worker-loader?publicPath=scripts/&name=worker.js!*" {
    class WebpackWorker extends Worker {
        constructor();
    }
    export = WebpackWorker;
}

To be closed, sorry about that.

@Melmoth-the-Wanderer Melmoth-the-Wanderer changed the title Options doesn't work with Typescript and Webpack 3 [FIXED] Options (name/publicPath) doesn't work with Typescript and Webpack 3 config file Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant