Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getWorkboxSWImport(compilation, config) {
switch (config.importWorkboxFrom) {
case 'cdn': {
return [getModuleUrl('workbox-sw')];
}
case 'local': {
// This will create a local copy of the Workbox runtime libraries in
// the output directory, independent of the webpack build pipeline.
// In general, this should work, but one thing to keep in mind is that
// when using the webpack-dev-server, the output will be created on
// disk, rather than in the in-memory filesystem. (webpack-dev-server will
// still be able to serve the runtime libraries from disk.)
const wbDir = await copyWorkboxLibraries(path.join(
compilation.options.output.path, config.importsDirectory));
// We need to set this extra option in the config to ensure that the
// workbox library loader knows where to get the local libraries from.
config.modulePathPrefix = (compilation.options.output.publicPath || '') +
path.join(config.importsDirectory, wbDir).split(path.sep).join('/');
async function getWorkboxSWImport(compilation, config) {
switch (config.importWorkboxFrom) {
case 'cdn': {
return [getModuleUrl('workbox-sw')];
}
case 'local': {
// This will create a local copy of the Workbox runtime libraries in
// the output directory, independent of the webpack build pipeline.
// In general, this should work, but one thing to keep in mind is that
// when using the webpack-dev-server, the output will be created on
// disk, rather than in the in-memory filesystem. (webpack-dev-server will
// still be able to serve the runtime libraries from disk.)
const wbDir = await copyWorkboxLibraries(compilation.options.output.path);
const workboxSWImport = (compilation.options.output.publicPath || '')
+ wbDir + '/workbox-sw.js';
// We need to set this extra option in the config to ensure that the
// workbox library loader knows where to get the local libraries from.
config.modulePathPrefix = wbDir;
return [workboxSWImport];
function getWorkboxSWImport(compilation, config) {
switch (config.importWorkboxFrom) {
case 'cdn': {
return [getModuleUrl('workbox-sw')];
}
case 'local': {
// TODO: Implement.
throw Error(`importWorkboxFrom 'local' is not yet supported.`);
}
case 'disabled': {
return null;
}
default: {
// If importWorkboxFrom is anything else, then treat it as the name of
// a webpack chunk that corresponds to the custom compilation of the
// Workbox code.
for (const chunk of compilation.chunks) {