imports-loader
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [1.1.0](https://github.com/webpack-contrib/imports-loader/compare/v1.0.0...v1.1.0) (2020-06-24) | ||
### Features | ||
* "|" character can be used as delimiter for inline string syntax ([00697de](https://github.com/webpack-contrib/imports-loader/commit/00697dee3d0108bf632b3f82bd3adc62bd7aa907)) | ||
## [1.0.0](https://github.com/webpack-contrib/imports-loader/compare/v0.8.0...v1.0.0) (2020-06-17) | ||
@@ -7,0 +14,0 @@ |
@@ -51,3 +51,3 @@ "use strict"; | ||
if (typeof options.additionalCode !== 'undefined') { | ||
importsCode += `\n${options.additionalCode}`; | ||
importsCode += `\n${options.additionalCode}\n`; | ||
} | ||
@@ -54,0 +54,0 @@ |
@@ -25,2 +25,14 @@ "use strict"; | ||
function splitCommand(command) { | ||
const result = command.split('|').map(item => item.split(' ')).reduce((acc, val) => acc.concat(val), []); | ||
for (const item of result) { | ||
if (!item) { | ||
throw new Error(`Invalid command "${item}" in "${command}" for imports. There must be only one separator: " ", or "|"`); | ||
} | ||
} | ||
return result; | ||
} | ||
function resolveImports(type, item) { | ||
@@ -37,3 +49,3 @@ const defaultSyntax = type === 'module' ? 'default' : 'single'; | ||
const splittedItem = noWhitespaceItem.split(' '); | ||
const splittedItem = splitCommand(noWhitespaceItem); | ||
@@ -40,0 +52,0 @@ if (splittedItem.length > 4) { |
{ | ||
"name": "imports-loader", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "imports loader module for webpack", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -49,15 +49,26 @@ <div align="center"> | ||
**index.js** | ||
The `|` or `%20` (space) allow to separate the `syntax`, `moduleName`, `name` and `alias` of import. | ||
The documentation and syntax examples can be read [here](#syntax). | ||
> ⚠ `%20` is space in a query string, because you can't use spaces in URLs | ||
```js | ||
import myLib from 'imports-loader?imports=default%20jquery%20$!./example.js'; | ||
// Alternative syntax: | ||
// | ||
// import myLib from 'imports-loader?imports=default%20jquery%20$!./example.js'; | ||
// | ||
// `%20` is space in a query string, equivalently `default jquery $` | ||
import myLib from 'imports-loader?imports=default|jquery|$!./example.js'; | ||
// Adds the following code to the beginning of example.js: | ||
// | ||
// import $ from "jquery";` to `example.js | ||
// import $ from "jquery"; | ||
// | ||
// ... | ||
// Code | ||
// ... | ||
``` | ||
```js | ||
import myLib from 'imports-loader?imports[]=default%20jquery%20$&imports[]=angular!./example.js'; | ||
// `%20` is space in a query string, equivalently `default jquery $` and `angular` | ||
import myLib from 'imports-loader?imports[]=default|jquery|$&imports[]=angular!./example.js'; | ||
// `|` is separator in a query string, equivalently `default|jquery|$` and `angular` | ||
// Adds the following code to the beginning of example.js: | ||
@@ -67,7 +78,11 @@ // | ||
// import angular from "angular"; | ||
// | ||
// ... | ||
// Code | ||
// ... | ||
``` | ||
```js | ||
import myLib from 'imports-loader?imports[]=named%20library%20myMethod&imports[]=angular!./example.js'; | ||
// `%20` is space in a query string, equivalently `default jquery $` and `angular` | ||
import myLib from 'imports-loader?imports[]=named|library|myMethod&imports[]=angular!./example.js'; | ||
// `|` is separator in a query string, equivalently `named|library|myMethod` and `angular` | ||
// Adds the following code to the beginning of example.js: | ||
@@ -77,7 +92,11 @@ // | ||
// import angular from "angular"; | ||
// | ||
// ... | ||
// Code | ||
// ... | ||
``` | ||
```js | ||
const myLib = require(`imports-loader?type=commonjs&imports[]=single%20jquery%20$&imports[]=angular!./example.js`); | ||
// `%20` is space in a query string, equivalently `single jquery $` and `angular` | ||
const myLib = require(`imports-loader?type=commonjs&imports[]=single|jquery|$&imports[]=angular!./example.js`); | ||
// `|` is separator in a query string, equivalently `single|jquery|$` and `angular` | ||
// Adds the following code to the beginning of example.js: | ||
@@ -87,7 +106,11 @@ // | ||
// var angular = require("angular"); | ||
// | ||
// ... | ||
// Code | ||
// ... | ||
``` | ||
```js | ||
const myLib = require(`imports-loader?type=commonjs&imports=single%20myLib%20myMethod&&wrapper=window&!./example.js`); | ||
// `%20` is space in a query string, equivalently `single jquery $` and `angular` | ||
const myLib = require(`imports-loader?type=commonjs&imports=single|myLib|myMethod&&wrapper=window&!./example.js`); | ||
// `|` is separator in a query string, equivalently `single|myLib|myMethod` and `angular` | ||
// Adds the following code to the example.js: | ||
@@ -104,2 +127,13 @@ // | ||
```js | ||
import myLib from 'imports-loader?additionalCode=var%20myVariable%20=%20false;!./example.js'; | ||
// Adds the following code to the beginning of example.js: | ||
// | ||
// var myVariable = false; | ||
// | ||
// ... | ||
// Code | ||
// ... | ||
``` | ||
### Using Configuration | ||
@@ -250,10 +284,10 @@ | ||
String values let you specify import `syntax`, `moduleName`, `name` and `alias`. | ||
The `|` or `%20` (space) allow to separate the `syntax`, `moduleName`, `name` and `alias` of import. | ||
String syntax - `[[syntax] [moduleName] [name] [alias]]`, where: | ||
String syntax - `[[syntax] [moduleName] [name] [alias]]` or `[[syntax]|[moduleName]|[name]|[alias]]`, where: | ||
- `[syntax]`: | ||
- `[syntax]` (**may be omitted**): | ||
- if `type` is `module`- can be `default`, `named`, `namespace` or `side-effects` | ||
- if `type` is `commonjs`- can be `single`, `multiple` or `pure` | ||
- if `type` is `module`- can be `default`, `named`, `namespace` or `side-effects`, the default value is `default`. | ||
- if `type` is `commonjs`- can be `single`, `multiple` or `pure`, the default value is `single`. | ||
@@ -260,0 +294,0 @@ - `[moduleName]` - name of an imported module (**required**) |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
34234
412
694
0