Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Worker - How to reference worker file when packaged with Bower

I'm writing a small javascript text expansion library. The library use a web worker and is packaged up with bower. When installed via bower the parser script is not found (I get a 404) because the browser is looking relative to the root of the consuming site and not relative to the bower script from which it is being consumed (both scripts are contained in the same folder). This appears to be the correct behavior.

My question: how should workers be used in combination with bower such that required scripts can be loaded without hard-coding the bower_components/ path?

function Expander(args) {
    ...
    this.parser = 'parser.js';
    this.worker = new Worker(this.parser);
    ...
}
like image 930
JP. Avatar asked Jun 29 '15 14:06

JP.


Video Answer


1 Answers

I would use Grunt. Gulp might be a bit easier starting out since it can be debugged but it is missing a key component for your needs. There are a set of libraries wiredep, build-file and watch that will enable you to do what you are wanting to do. Wiredep watches the bower directory and will automatically add the js files for the dependencies in bower.json into the html and watch can be configured to watch any type of file in any directory for a change. Build-file enables you to configure a template and pass it variables that it will use to dynamically build a js file. You can then use the abilities of grunt to get the correct application path and point it to your file.

like image 76
tuckerjt07 Avatar answered Nov 07 '22 06:11

tuckerjt07