imports-loader
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [1.2.0](https://github.com/webpack-contrib/imports-loader/compare/v1.1.0...v1.2.0) (2020-10-07) | ||
### Features | ||
* add custom parameter names for wrapper args ([#86](https://github.com/webpack-contrib/imports-loader/issues/86)) ([4314ecd](https://github.com/webpack-contrib/imports-loader/commit/4314ecd2b853dec1a4f5a3fa76f8559167732cb5)) | ||
## [1.1.0](https://github.com/webpack-contrib/imports-loader/compare/v1.0.0...v1.1.0) (2020-06-24) | ||
@@ -7,0 +14,0 @@ |
@@ -12,3 +12,3 @@ "use strict"; | ||
var _schemaUtils = _interopRequireDefault(require("schema-utils")); | ||
var _schemaUtils = require("schema-utils"); | ||
@@ -29,3 +29,3 @@ var _options = _interopRequireDefault(require("./options.json")); | ||
const options = (0, _loaderUtils.getOptions)(this); | ||
(0, _schemaUtils.default)(_options.default, options, { | ||
(0, _schemaUtils.validate)(_options.default, options, { | ||
name: 'Imports Loader', | ||
@@ -61,8 +61,11 @@ baseDataPath: 'options' | ||
let args; | ||
let params; | ||
if (typeof options.wrapper === 'boolean') { | ||
thisArg = ''; | ||
params = ''; | ||
args = ''; | ||
} else if (typeof options.wrapper === 'string') { | ||
thisArg = options.wrapper; | ||
params = ''; | ||
args = ''; | ||
@@ -74,6 +77,13 @@ } else { | ||
} = options.wrapper); | ||
args = args.join(', '); | ||
if (Array.isArray(args)) { | ||
params = args.join(', '); | ||
args = params; | ||
} else { | ||
params = Object.keys(args).join(', '); | ||
args = Object.values(args).join(', '); | ||
} | ||
} | ||
importsCode += `\n(function(${args}) {`; | ||
importsCode += `\n(function(${params}) {`; | ||
codeAfterModule += `\n}.call(${thisArg}${args ? `, ${args}` : ''}));\n`; | ||
@@ -80,0 +90,0 @@ } |
@@ -85,8 +85,16 @@ { | ||
"args": { | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
"anyOf": [ | ||
{ | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
}, | ||
{ | ||
"type": "object", | ||
"additionalProperties": true | ||
} | ||
] | ||
} | ||
@@ -93,0 +101,0 @@ }, |
{ | ||
"name": "imports-loader", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "imports loader module for webpack", | ||
@@ -45,3 +45,3 @@ "license": "MIT", | ||
"loader-utils": "^2.0.0", | ||
"schema-utils": "^2.7.0", | ||
"schema-utils": "^3.0.0", | ||
"source-map": "^0.6.1", | ||
@@ -51,25 +51,25 @@ "strip-comments": "^2.0.1" | ||
"devDependencies": { | ||
"@babel/cli": "^7.10.1", | ||
"@babel/core": "^7.10.2", | ||
"@babel/preset-env": "^7.10.2", | ||
"@commitlint/cli": "^8.3.5", | ||
"@commitlint/config-conventional": "^8.3.4", | ||
"@babel/cli": "^7.11.6", | ||
"@babel/core": "^7.11.6", | ||
"@babel/preset-env": "^7.11.5", | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0", | ||
"@webpack-contrib/defaults": "^6.3.0", | ||
"@webpack-contrib/eslint-config-webpack": "^3.0.0", | ||
"babel-jest": "^26.0.1", | ||
"babel-jest": "^26.5.2", | ||
"babel-loader": "^8.1.0", | ||
"cross-env": "^7.0.2", | ||
"del": "^5.1.0", | ||
"del": "^6.0.0", | ||
"del-cli": "^3.0.1", | ||
"eslint": "^7.2.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-import": "^2.21.2", | ||
"husky": "^4.2.5", | ||
"jest": "^26.0.1", | ||
"lint-staged": "^10.2.9", | ||
"eslint": "^7.10.0", | ||
"eslint-config-prettier": "^6.12.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"husky": "^4.3.0", | ||
"jest": "^26.5.2", | ||
"lint-staged": "^10.4.0", | ||
"memfs": "^3.2.0", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.0.5", | ||
"standard-version": "^8.0.0", | ||
"webpack": "^4.43.0" | ||
"prettier": "^2.1.2", | ||
"standard-version": "^9.0.0", | ||
"webpack": "^4.44.2" | ||
}, | ||
@@ -76,0 +76,0 @@ "keywords": [ |
@@ -625,2 +625,48 @@ <div align="center"> | ||
#### `Object` with different parameter names | ||
**webpack.config.js** | ||
```js | ||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: require.resolve('example.js'), | ||
use: [ | ||
{ | ||
loader: 'imports-loader', | ||
options: { | ||
imports: { | ||
moduleName: 'jquery', | ||
name: '$', | ||
}, | ||
wrapper: { | ||
thisArg: 'window', | ||
args: { | ||
myVariable: 'var1', | ||
myOtherVariable: 'var2', | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}; | ||
``` | ||
Generate output: | ||
```js | ||
import $ from 'jquery'; | ||
(function (var1, var2) { | ||
// ... | ||
// Code | ||
// ... | ||
}.call(window, myVariable, myOtherVariable)); | ||
``` | ||
### `additionalCode` | ||
@@ -631,4 +677,8 @@ | ||
Adds custom code. | ||
Adds custom code as a preamble before the module's code. | ||
##### Examples | ||
###### Define custom variable | ||
**webpack.config.js** | ||
@@ -672,2 +722,43 @@ | ||
###### Disable AMD Import Syntax | ||
**webpack.config.js** | ||
```js | ||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: require.resolve('example.js'), | ||
use: [ | ||
{ | ||
loader: 'imports-loader', | ||
options: { | ||
imports: { | ||
moduleName: 'jquery', | ||
name: '$', | ||
}, | ||
additionalCode: | ||
'var define = false; /* Disable AMD for misbehaving libraries */', | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}; | ||
``` | ||
Generate output: | ||
```js | ||
import $ from 'jquery'; | ||
var define = false; /* Disable AMD for misbehaving libraries */ | ||
// ... | ||
// Code | ||
// ... | ||
``` | ||
## Contributing | ||
@@ -674,0 +765,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36563
429
785
- Removedschema-utils@2.7.1(transitive)
Updatedschema-utils@^3.0.0