New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

magic-comments-loader

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magic-comments-loader - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

dist/webpackIgnore.js

2

dist/package.json
{
"name": "magic-comments-loader",
"version": "1.0.0",
"version": "1.1.0",
"description": "Add webpack magic comments to your dynamic imports during build time",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -12,6 +12,9 @@ "use strict";

var _webpackIgnore = require("./webpackIgnore.js");
const commentFor = {
webpackChunkName: _webpackChunkName.webpackChunkName,
webpackMode: _webpackMode.webpackMode
webpackMode: _webpackMode.webpackMode,
webpackIgnore: _webpackIgnore.webpackIgnore
};
exports.commentFor = commentFor;

@@ -6,3 +6,3 @@ "use strict";

});
exports.getOverrideConfig = void 0;
exports.filepathIsMatch = exports.getOverrideConfig = void 0;

@@ -17,21 +17,3 @@ var _micromatch = _interopRequireDefault(require("micromatch"));

for (let i = 0; i < length; i++) {
let {
files
} = overrides[i];
let globs = [];
let notglobs = [];
if (!Array.isArray(files)) {
files = [files];
}
files.forEach(file => {
if (/^!/.test(file)) {
notglobs.push(file);
} else {
globs.push(file);
}
});
if ((globs.length === 0 || globs.some(glob => _micromatch.default.isMatch(filepath, glob))) && notglobs.every(notglob => _micromatch.default.isMatch(filepath, notglob))) {
if (filepathIsMatch(filepath, overrides[i].files)) {
return { ...config,

@@ -46,2 +28,22 @@ ...overrides[i].config

exports.getOverrideConfig = getOverrideConfig;
exports.getOverrideConfig = getOverrideConfig;
const filepathIsMatch = (filepath, files) => {
const globs = [];
const notglobs = [];
if (!Array.isArray(files)) {
files = [files];
}
files.forEach(file => {
if (/^!/.test(file)) {
notglobs.push(file);
} else {
globs.push(file);
}
});
return (globs.length === 0 || globs.some(glob => _micromatch.default.isMatch(filepath, glob))) && notglobs.every(notglob => _micromatch.default.isMatch(filepath, notglob));
};
exports.filepathIsMatch = filepathIsMatch;
{
"name": "magic-comments-loader",
"version": "1.0.0",
"version": "1.1.0",
"description": "Add webpack magic comments to your dynamic imports during build time",

@@ -5,0 +5,0 @@ "main": "dist",

# magic-comments-loader
Adds [magic coments](https://webpack.js.org/api/module-methods/#magic-comments) to your dynamic import statements. Currently only supports `webpackChunkName` and `webpackMode`.
Adds [magic coments](https://webpack.js.org/api/module-methods/#magic-comments) to your dynamic import statements.
**NOTE**: This loader ignores dynamic imports that already include comments of any kind.
Magic comments supported:
* `webpackChunkName`
* `webpackMode`
* `webpackIgnore`
## Usage

@@ -41,4 +49,5 @@

options: {
webpackChunkName: true
webpackMode: 'lazy'
webpackChunkName: true,
webpackMode: 'lazy',
webpackIgnore: 'src/ignore/**/*.js'
}

@@ -55,10 +64,37 @@ }

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:
```js
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'magic-comments-loader',
options: {
webpackChunkName: {
basename: true
},
webpackMode: {
mode: 'lazy-once'
},
webpackIgnore: {
active: false
}
}
}
}
]
}
```
```
You can also override the configuration passed in the `config` key by using the `overrides` key, which is an array of objects that look like:
```js
overrides: [
{
files: ['src/**/*.js', '!/src/skip/**/*.js'] // Uses micromatch,
// Array of globs or a specific file (can be a string too)
// Uses micromatch to compare the module filepath to the provided string
files: ['src/**/*.js', '!/src/skip/**/*.js']
// Other configuration keys for the comment type can go here too
config: {
// Other configuration keys for the comment type can go here too
active: false

@@ -70,3 +106,3 @@ }

Here's a more complete example:
Here's a more complete example using comment `config` and `overrides`:

@@ -133,3 +169,3 @@ ```js

With loader options configured like:
With loader options configured like

@@ -146,3 +182,3 @@ ```js

An import statement like:
an import statement like

@@ -153,3 +189,3 @@ ```js

Becomes:
becomes

@@ -159,1 +195,22 @@ ```js

```
### Options
These are the options that can be configured under the loader `options`.
* `verbose`: Prints console statements of the updated `import()`s per module filepath during the webpack build. Useful for debugging your custom configurations.
* `webpackChunkName`
* `true`: Adds `webpackChunkName` comments to **all** dynamic imports using the full path to the imported module to construct the name, so `import('path/to/module')` becomes `import(/* webpackChunkName: "path-to-module" */ 'path/to/module')`. This is the default.
* `false`: Disables adding the `webpackChunkName` comment globally.
* `config.active`: Boolean to enable/disable the comment.
* `config.basename`: Boolean to use only the basename from the import path as the chunk name. Some relative path imports may end up with the same basename depsite importing different modules. Use in areas where you know the basenames are unique.
* `webpackMode`
* `true`: Adds `webpackMode` comments to **all** dynamic imports using `lazy` so `import('path/to/module')` becomes `import(/* webpackMode: "lazy" */ 'path/to/module')`.
* `false`: Disables adding the `webpackChunkName` comment globally. This is the default.
* `config.active`: Boolean to enable/disable the comment.
* `config.mode`: String to set the mode. `lazy`, `lazy-once`, `eager`, or `weak`.
* `webpackIgnore`
* `true`: Adds `webpackIgnore` comments to **all** dynamic imports `true` so `import('path/to/module')` becomes `import(/* webpackIgnore: true */ 'path/to/module')`.
* `false`: Disables adding the `webpackIgnore` comment globally. This is the default.
* `some/glob/**/*.js`|`['/some/globs/**/*.js']`: Adds the comment with a value of `true` to all module filepaths that match the string or array of strings.
* `config.active`: Boolean to enable/disable the comment.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc