Open ddumont opened 6 years ago
Feel free to take this approach for your plugin. I find that I have way more control over how my serviceworker gets packed this way. The sourcemaps also work perfectly now... well... as well as they do for everything else ;)
Ah ha! I almost forgot. You have to do a bit more work when using hot module replace for your main code. (I'm not sure I want to think about doing this with the service worker.... I guess it can work?)
// my express server
if (config.get('dev:devmode')) {
const webpack = require('webpack');
const wdm = require('webpack-dev-middleware');
const whm = require('webpack-hot-middleware');
const wpconf = require('./webpack.config');
const compiler = webpack(wpconf[0]);
app.use(wdm(compiler, { publicPath: '/' }));
app.use(whm(compiler));
app.use(wdm(webpack(wpconf[1]), { publicPath: '/' }));
}
Without this, wdm/whm gets very upset about changes in your service worker, if you passed it the whole array of webpack confs as the compiler.
I tried playing around with this plugin over the weekend and ran into a few issues. One was just getting a better understanding of service workers :), but it was really hard to do because sourcemaps are completely borked because of the way this plugin operates.
So I did a bit of tinkering around, and I found out a few things.
Cool... so I've squirreled away, in a really hackey way, the assets for the main layer! But the service worker config finishes waaaaaaay before the main one... so here's another small hack, and my loader.