Auto-Generated import for precache-manifest pointing to the wrong location
Library Affected: workbox-webpack-plugin
Browser & Platform: All browsers
Issue or Feature Request Description: I'm using Webpack with an Asp.net core project. Calling WorkBoxPlugin.GenerateSW() succesfully generates the service-worker file - but with an invalid import location for the precache manifest.
Webpack config:
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const bundleOutputDir = './wwwroot/dist';
const WorkboxPlugin = require('workbox-webpack-plugin');
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
return [{
stats: { modules: false },
context: __dirname,
resolve: { extensions: [ '.js', '.ts' ] },
entry: { 'main': './ClientApp/boot.ts' },
module: {
rules: [
{ test: /\.vue$/, include: /ClientApp/, loader: 'vue-loader', options: { loaders: { js: 'awesome-typescript-loader' }, appendTsSuffixTo: [/\.vue$/] } },
{ test: /\.ts$/, include: /ClientApp/, loader: 'ts-loader', options: {appendTsSuffixTo: [/\.vue$/] } },
{ test: /\.css$/, use: isDevBuild ? [ 'style-loader', 'css-loader' ] : ExtractTextPlugin.extract({ use: 'css-loader?minimize' }) },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
{
test: /\.less$/,
use: isDevBuild ? [
{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "less-loader"
}
] : ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader?minimize!less-loader' })
}
]
},
output: {
path: path.join(__dirname, bundleOutputDir),
filename: '[name].js',
publicPath: 'dist/'
},
plugins: [
new CheckerPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(isDevBuild ? 'development' : 'production')
}
}),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
}),
new WorkboxPlugin.GenerateSW({
swDest: 'sw.js'
})
].concat(isDevBuild ? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
new webpack.optimize.UglifyJsPlugin(),
new ExtractTextPlugin('site.css')
])
}];
};
Output sw.js:
/**
* Welcome to your Workbox-powered service worker!
*
* You'll need to register this file in your web app and you should
* disable HTTP caching for this file too.
* See https://goo.gl/nhQhGp
*
* The rest of the code is auto-generated. Please don't update this file
* directly; instead, make changes to your Workbox build configuration
* and re-run your build process.
* See https://goo.gl/2aRDsh
*/
importScripts("https://storage.googleapis.com/workbox-cdn/releases/3.1.0/workbox-sw.js");
importScripts(
"dist/precache-manifest.d9e8afffebe20bbf64194d40d6949d72.js"
);
/**
* The workboxSW.precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
*/
self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.suppressWarnings();
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
The import is from dist/precache-manifest... - which when running results in the browser trying to fetch the manifest from /dist/dist/precache-manifest... since the sw.js file is already in /dist
I imagine I'm just configuring it incorrectly but I can't find any information about setting the precache-manifest location?
Many thanks!
Nb. I worked around this by moving the sw.js output up a directory (Duh! - not enough coffee) - still curious if it's possible if sw.js and prechache-manifest are in the same folder though?