Skip to content

Commit

Permalink
chore(release): 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Jun 24, 2020
1 parent 00697de commit afc1998
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [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)


Expand Down
48 changes: 38 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,25 @@ Then you can inject the `jquery` value into the module by configuring the `impor

### Inline

The `|` or `%20` (space) separate command parts.
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
**index.js**

```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";
//
// ...
// Code
// ...
```

```js
Expand All @@ -67,6 +74,10 @@ import myLib from 'imports-loader?imports[]=default|jquery|$&imports[]=angular!.
//
// import $ from "jquery";
// import angular from "angular";
//
// ...
// Code
// ...
```

```js
Expand All @@ -76,6 +87,10 @@ import myLib from 'imports-loader?imports[]=named|library|myMethod&imports[]=ang
//
// import { myMethod } from "library";
// import angular from "angular";
//
// ...
// Code
// ...
```

```js
Expand All @@ -85,6 +100,10 @@ const myLib = require(`imports-loader?type=commonjs&imports[]=single|jquery|$&im
//
// var $ = require("jquery");
// var angular = require("angular");
//
// ...
// Code
// ...
```

```js
Expand All @@ -101,6 +120,17 @@ const myLib = require(`imports-loader?type=commonjs&imports=single|myLib|myMetho
// }.call(window));
```

```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

**webpack.config.js**
Expand Down Expand Up @@ -246,16 +276,14 @@ Allows to use a string to describe an export.

##### `Syntax`

The `" "` or `|` (space) separate command parts.

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]]` 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`.

- `[moduleName]` - name of an imported module (**required**)
- `[name]` - name of an imported value (**required**)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imports-loader",
"version": "1.0.0",
"version": "1.1.0",
"description": "imports loader module for webpack",
"license": "MIT",
"repository": "webpack-contrib/imports-loader",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function loader(content, sourceMap) {
}

if (typeof options.additionalCode !== 'undefined') {
importsCode += `\n${options.additionalCode}`;
importsCode += `\n${options.additionalCode}\n`;
}

let codeAfterModule = '';
Expand Down
18 changes: 18 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ exports[`loader should work with "imports", "wrapper" and "additionalCode" optio
import \\"lib_1\\";
var someVariable = 1;
(function() {
var someCode = {
number: 123,
Expand Down Expand Up @@ -892,6 +893,22 @@ var someCode = {

exports[`loader should work with inline syntax #2: warnings 1`] = `Array []`;

exports[`loader should work with inline syntax #3: errors 1`] = `Array []`;

exports[`loader should work with inline syntax #3: module 1`] = `
"/*** IMPORTS FROM imports-loader ***/
var require = false;
var someCode = {
number: 123,
object: { existingSubProperty: 123 }
};
"
`;

exports[`loader should work with inline syntax #3: warnings 1`] = `Array []`;

exports[`loader should work with inline syntax: errors 1`] = `Array []`;

exports[`loader should work with inline syntax: module 1`] = `
Expand Down Expand Up @@ -1103,6 +1120,7 @@ exports[`loader should work with the "additionalCode" option: module 1`] = `
"/*** IMPORTS FROM imports-loader ***/
var someVariable = 1;
var someCode = {
number: 123,
object: { existingSubProperty: 123 }
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/inline4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('../../src/cjs.js?additionalCode=var%20require%20=%20false;!./some-library.js');
11 changes: 11 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,17 @@ describe('loader', () => {
expect(getWarnings(stats)).toMatchSnapshot('warnings');
});

it('should work with inline syntax #3', async () => {
const compiler = getCompiler('inline4.js', {}, {}, true);
const stats = await compile(compiler);

expect(getModuleSource('./some-library.js', stats)).toMatchSnapshot(
'module'
);
expect(getErrors(stats)).toMatchSnapshot('errors');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
});

it('should throw error on invalid inline syntax', async () => {
const compiler = getCompiler('inline-broken.js', {}, {}, true);
const stats = await compile(compiler);
Expand Down

0 comments on commit afc1998

Please sign in to comment.