diff --git a/index.js b/index.js index d023717..f71252e 100644 --- a/index.js +++ b/index.js @@ -112,7 +112,7 @@ function MomentLocalesPlugin(options) { return new ContextReplacementPlugin( /moment[\/\\]locale/, - new RegExp('(' + regExpPatterns.join('|') + ')$') + new RegExp('[/\\\\](' + regExpPatterns.join('|') + ')$') ); } else { return new IgnorePlugin(/^\.\/locale$/, /moment$/); diff --git a/package.json b/package.json index ee7c390..019a07f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moment-locales-webpack-plugin", - "version": "1.1.1-0", + "version": "1.1.1", "description": "Strip unused locales from Moment.js", "main": "index.js", "scripts": { diff --git a/test/test.js b/test/test.js index d314692..b6a873e 100644 --- a/test/test.js +++ b/test/test.js @@ -82,6 +82,24 @@ describe('webpack build', () => { expect(localeModules).toHaveLength(1); expect(localeModules[0]).toMatch('moment/locale/en-gb'); }); + + // Covers https://github.com/iamakulov/moment-locales-webpack-plugin/issues/13 + test('doesn’t include locales whose names intersect with a passed locale', async () => { + const modulePaths = await runWithWebpack({ + localesToKeep: ['ca'], + }); + + const momentModule = modulePaths.find(path => + path.includes('moment/moment.js') + ); + expect(momentModule).toBeTruthy(); + + const localeModules = modulePaths.filter(path => + path.includes(`moment/locale`) + ); + expect(localeModules).toHaveLength(1); + expect(localeModules[0]).toMatch('moment/locale/ca'); + }); }); describe('validation', () => {