dynamic imports require a leading comment with the webpackChunkName (dynamic-import-requires-webpack-chunkname)
Ensure proper usage of dynamic imports. It requires exactly one argument with a leading comment including the webpackChunkName so that webpack doesn't auto-generate the chunkname.
This rule can be configured with options to run against any import replacement function - in our case, dynamicImport
.
{
"dynamic-import-requires-webpack-chunkname": [2, { importReplacement: "dynamicImport" }]
}
The following patterns are considered warnings:
// no leading comment with chunkname
dynamicImport('someModule');
// leading comment, but two arguments
dynamicImport(
/* webpackChunkName: "someModule" */
'someModule',
'someOtherModule'
);
// incorrectly formatted leading comment
dynamicImport(
/*webpackChunkName:"someModule"*/
'someModule',
);
// incorrectly formatted leading comment
dynamicImport(
/* webpackChunkName: 'someModule' */
'someModule',
);
// correctly formatted leading comment, argument is not a string
dynamicImport(
/* webpackChunkName: "someModule" */
someModule,
);
// using a single-line comment, not a block-style comment
dynamicImport(
// webpackChunkName: "someModule"
'someModule',
);
The following patterns are not warnings:
dynamicImport(
/* webpackChunkName: "someModule" */
'someModule',
);
dynamicImport(
/* webpackChunkName: "Some_Other_Module" */
'someOtherModule',
);