Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
magic-comments-loader
Advanced tools
Add webpack magic comments to your dynamic imports during build time
Adds magic coments to your dynamic import statements. Currently only supports webpackChunkName
and webpackMode
.
First npm install magic-comments-loader
.
Add this inside your webpack.config.js
.
Adds webpackChunkName
to all dynamic imports (same as webpackChunkName: true
when using options).
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['magic-comments-loader']
}
]
}
When using the loaders options
configure the magic comments by using their name as a key in the options object. You can provide a simple value to take on default behavior of the comment.
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'magic-comments-loader',
options: {
webpackChunkName: true
webpackMode: 'lazy'
}
}
}
]
}
For more control you can provide an object literal with futher configuration options specific
to each comment type. All comment types have a configuration option of active
which is a boolean to enable
or disable the addition of the magic comment. When using an object literal the configuration must be passed under the config
key.
You can also override the configuration passed in the config
key by file location when using the overrides
key, which is an array of objects that look like:
overrides: [
{
files: ['src/**/*.js', '!/src/skip/**/*.js'] // Uses micromatch,
config: {
// Other configuration keys for the comment type can go here too
active: false
}
}
]
Here's a more complete example:
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'magic-comments-loader',
options: {
verbose: true,
webpackChunkName: {
config: {
basename: false
},
overrides: [
{
files: 'src/unique/**/*.js',
config: {
basename: true
}
},
{
files: 'src/off/**/*.js',
config: {
active: false
}
}
]
},
webpackMode: {
config: {
mode: 'lazy'
},
overrides: [
{
files: 'src/noMode/**/*.js',
config: {
active: false
}
},
{
files: [
'src/**/*.js',
'!src/weak/**/*.js'
],
config: {
mode: 'eager'
}
}
]
}
}
}
}
]
}
With loader options configured like:
{
loader: 'magic-comments-loader',
options: {
webpackChunkName: true,
webpackMode: 'lazy'
}
}
An import statement like:
const dynamicModule = await import('./path/to/some/module')
Becomes:
const dynamicModule = await import(/* webpackChunkName: "path-to-some-module", webpackMode: "lazy" */ './path/to/some/module')
FAQs
Add webpack magic comments to your dynamic imports at build time.
The npm package magic-comments-loader receives a total of 1,487 weekly downloads. As such, magic-comments-loader popularity was classified as popular.
We found that magic-comments-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.