chore: 调整workbox的正则表达式

pull/13/head
moonrailgun 3 years ago
parent 021b1906f9
commit d57a091d2d

@ -0,0 +1,14 @@
import { workboxPluginPattern } from '../utils';
describe('workboxPluginPattern', () => {
test.each([
['/plugins/com.msgbyte.foo/bar.js', true],
['/plugins/com.msgbyte.foo.foz/bar.js', true],
['/plugins/com.msgbyte.foo/index.js', false],
['/plugins/com.msgbyte.foo/index-abcde.js', false], // TODO: 这个期望是true的。但是不会写正则
['/plugins/com.msgbyte.foo/index.woff', false],
['/plugins/com.msgbyte.foo/font.woff', false],
])('%s: %p', (input, output) => {
expect(workboxPluginPattern.test(input)).toBe(output);
});
});

@ -0,0 +1,5 @@
/**
* workbox plugin
*/
export const workboxPluginPattern =
/plugins\/com\.msgbyte(.*?)\/((?!index).)*?\.js/;

@ -12,6 +12,7 @@ import CopyPlugin from 'copy-webpack-plugin';
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import fs from 'fs';
import WorkboxPlugin from 'workbox-webpack-plugin';
import { workboxPluginPattern } from './utils';
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('dotenv').config();
@ -185,7 +186,7 @@ const config: Configuration = {
},
{
// 匹配内置 plugins 以加速
urlPattern: /plugins\/com\.msgbyte(.*?)\.js/,
urlPattern: workboxPluginPattern,
handler: 'CacheFirst',
options: {
cacheName: 'builtin-plugins',

Loading…
Cancel
Save