Open alippai opened 9 years ago
@alippai can you show me some configuration ?
ping @alippai
ping @alippai
@arthurvr, @stephanebachelier: Here is a sample block inside a worker (say worker.js
)
/* build:js js/app.js */
importScripts("js/app.js")
importScripts("js/controllers/thing-controller.js")
importScripts("js/models/thing-model.js", "js/views/thing-view.js")
/* endbuild */
Grunt task configuration
useminPrepare: {
js: 'worker.js'
}
:+1:
I made a very ugly workaround that makes it possible to use usemin for WebWorker. I hope that there will be a nicer way to do this in the future. Hope someone can have use of it.
worker.js
// It is important that worker is in the root folder (like index.html)
// for the usemin build script to work properly
// <!-- build:js js/appAndWorker.js -->
var sources = ['src="bower_components/moment/moment.js"',
'src="bower_components/bluebird/js/browser/bluebird.js"'];
sources.forEach(function (source) {
source = /src="(.+)"/.exec(source)[1];
importScripts(source);
});
// <!-- endbuild -->
Gruntfile:
grunt.initConfig({
...
filerev: {
files: {
src: 'dist/js/appAndWorker.js'
}
},
useminPrepare: {
js: 'app/worker.js'
},
usemin: {
html: ['dist/index.html'],
js: {
src: 'dist/worker.js',
options: {
patterns: {
js: [
[/importScripts\(['"]([^"']+)["']/gm,
'Update the Worker with the new revved filename'
]
]
},
blockReplacements: {
js: function (block) {
return 'importScripts("' + block.dest + '");';
}
}
}
}
}
...
});
:thumbsup: @hacker112 I assume that work around is only for the filename replacement part, have you had any success/worked with adding the files inside sources to the concat part and/or worked with the filerev? I assume that wouldn't work either?
@solgarius I missed the filerev and useminPrepare in my example code. It is now updated. The concatenation of files and filerev works for me also.
@hacker112 Thanks, greatly appreciate this work around.
As only HTML comment blocks are supported you can't process blocks in JS Web Workers. Can you add support for
/* build: ... */
blocks next to the HTML's<!-- build: ... -->
?