sw.config.js 827 Bytes
const {InjectManifest} = require('workbox-webpack-plugin');
const path = require('path');
const isDev = process.env.NODE_ENV === 'dev' || !process.env.NODE_ENV;
const suffix = isDev ? 'dev' : 'prod';

module.exports = new InjectManifest({
    importWorkboxFrom: 'disabled',
    swSrc: path.join(__dirname, './sw.js'),
    swDest: isDev ? 'sw.js' : path.join(__dirname, '../public/static/sw.js'),
    chunks: ['index', 'page.common.offline.js', 'page.common.offline'],
    importScripts: [
        'https://cdn.yoho.cn/workbox/workbox-sw.js',
        `https://cdn.yoho.cn/workbox/workbox-core.${suffix}.js`,
        `https://cdn.yoho.cn/workbox/workbox-precaching.${suffix}.js`,
        `https://cdn.yoho.cn/workbox/workbox-routing.${suffix}.js`,
        `https://cdn.yoho.cn/workbox/workbox-cache-expiration.${suffix}.js`]
});