diff --git a/src/rules/dynamic-import-chunkname.js b/src/rules/dynamic-import-chunkname.js index 12394a1922..7bf13f4894 100644 --- a/src/rules/dynamic-import-chunkname.js +++ b/src/rules/dynamic-import-chunkname.js @@ -1,14 +1,6 @@ import vm from 'vm'; import docsUrl from '../docsUrl'; -function generateRegexForMagicComments(magicComments) { - const preparedComments = magicComments.map(([comment, value]) => { - return `(${comment}: ${value})`; - }); - - return new RegExp(`^( (${preparedComments.join('|')}),?)+ $`); -} - module.exports = { meta: { type: 'suggestion', @@ -36,18 +28,9 @@ module.exports = { const config = context.options[0]; const { importFunctions = [] } = config || {}; const { webpackChunknameFormat = '([0-9a-zA-Z-_/.]|\\[(request|index)\\])+' } = config || {}; - const webpackMagicComments = [ - ['webpackChunkName', `["']${webpackChunknameFormat}["']`], - ['webpackPrefetch', '(true|false|-?[0-9]+)'], - ['webpackPreload', '(true|false|-?[0-9]+)'], - ['webpackIgnore', '(true|false)'], - ['webpackInclude', '\\/.*\\/'], - ['webpackExclude', '\\/.*\\/'], - ['webpackMode', `["'](lazy|lazy-once|eager|weak)["']`], - ['webpackExports', `(['"]\\w+['"]|\\[(['"]\\w+['"], *)+(['"]\\w+['"]*)\\])`], - ]; + const paddedCommentRegex = /^ (\S[\s\S]+\S) $/; - const commentStyleRegex = generateRegexForMagicComments(webpackMagicComments); + const commentStyleRegex = /^( ((webpackChunkName: ["']([0-9a-zA-Z-_/.]|\[(request|index)\])+["'])|((webpackPrefetch|webpackPreload): (true|false|-?[0-9]+))|(webpackIgnore: (true|false))|((webpackInclude|webpackExclude): \/.*\/)|(webpackMode: ["'](lazy|lazy-once|eager|weak)["'])|(webpackExports: (['"]\w+['"]|\[(['"]\w+['"], *)+(['"]\w+['"]*)\]))),?)+ $/; const chunkSubstrFormat = ` webpackChunkName: ["']${webpackChunknameFormat}["'],? `; const chunkSubstrRegex = new RegExp(chunkSubstrFormat);