Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: webpack-contrib/file-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.0.1
Choose a base ref
...
head repository: webpack-contrib/file-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Nov 25, 2019

  1. Copy the full SHA
    6431101 View commit details
  2. chore(release): 5.0.2

    alexander-akait committed Nov 25, 2019
    Copy the full SHA
    f1b071c View commit details
  3. Copy the full SHA
    190829e View commit details

Commits on Dec 30, 2019

  1. Copy the full SHA
    5ffac2e View commit details
  2. Copy the full SHA
    521bff2 View commit details

Commits on Feb 19, 2020

  1. Copy the full SHA
    5703c58 View commit details
  2. Copy the full SHA
    cd8698b View commit details
  3. chore(release): 5.1.0

    alexander-akait committed Feb 19, 2020
    Copy the full SHA
    c2aded7 View commit details

Commits on Mar 17, 2020

  1. docs: update README.md (#368)

    xoyimi authored Mar 17, 2020
    Copy the full SHA
    e1fe27c View commit details
  2. chore(deps): update (#369)

    BREAKING CHANGE: use `md4` by default for hashing
    evilebottnawi authored Mar 17, 2020
    Copy the full SHA
    ad39022 View commit details
  3. chore(release): 6.0.0

    alexander-akait committed Mar 17, 2020
    Copy the full SHA
    e44eb73 View commit details

Commits on Apr 24, 2020

  1. Copy the full SHA
    3846b33 View commit details

Commits on Jun 22, 2020

  1. Copy the full SHA
    8bc9950 View commit details
  2. Copy the full SHA
    718aef5 View commit details

Commits on Aug 31, 2020

  1. Copy the full SHA
    40fcde8 View commit details
  2. test: fix

    evilebottnawi authored Aug 31, 2020
    Copy the full SHA
    6e22f6e View commit details
  3. chore(release): 6.1.0

    alexander-akait committed Aug 31, 2020
    Copy the full SHA
    25e2668 View commit details

Commits on Oct 9, 2020

  1. chore(deps): update

    evilebottnawi authored Oct 9, 2020
    Copy the full SHA
    60508cf View commit details
  2. Copy the full SHA
    6fadfbe View commit details

Commits on Oct 13, 2020

  1. Copy the full SHA
    14ed4c9 View commit details

Commits on Oct 27, 2020

  1. Copy the full SHA
    381d8bd View commit details
  2. Copy the full SHA
    654e0d6 View commit details
  3. chore(release): 6.2.0

    alexander-akait committed Oct 27, 2020
    Copy the full SHA
    c423008 View commit details

Commits on Jan 15, 2021

  1. Copy the full SHA
    467e6b7 View commit details

Commits on Feb 12, 2021

  1. docs: spelling (#403)

    marcusds authored Feb 12, 2021
    Copy the full SHA
    ceaa8d4 View commit details

Commits on Feb 24, 2021

  1. docs: fix typo (#404)

    jacob-lcs authored Feb 24, 2021
    Copy the full SHA
    a4840b3 View commit details

Commits on Mar 5, 2021

  1. Copy the full SHA
    59df66a View commit details
95 changes: 95 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: file-loader

on:
push:
branches:
- master
- next
pull_request:
branches:
- master
- next

jobs:
lint:
name: Lint - ${{ matrix.os }} - Node v${{ matrix.node-version }}

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

strategy:
matrix:
os: [ubuntu-latest]
node-version: [12.x]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ env.node-version }}

- name: Use latest NPM
run: sudo npm i -g npm

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Security audit
run: npm run security

- name: Check commit message
uses: wagoid/commitlint-github-action@v1

test:
name: Test - ${{ matrix.os }} - Node v${{ matrix.node-version }}, Webpack ${{ matrix.webpack-version }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [10.x, 12.x, 14.x]
webpack-version: [4, latest]

runs-on: ${{ matrix.os }}

steps:
- name: Setup Git
if: matrix.os == 'windows-latest'
run: git config --global core.autocrlf input

- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Use latest NPM on ubuntu/macos
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
run: sudo npm i -g npm

- name: Use latest NPM on windows
if: matrix.os == 'windows-latest'
run: npm i -g npm

- name: Install dependencies
run: npm ci

- name: Install webpack ${{ matrix.webpack-version }}
run: npm i webpack@${{ matrix.webpack-version }}

- name: Run tests for webpack version ${{ matrix.webpack-version }}
run: npm run test:coverage -- --ci

- name: Submit coverage data to codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
5 changes: 0 additions & 5 deletions .prettierrc

This file was deleted.

6 changes: 1 addition & 5 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
singleQuote: true,
trailingComma: 'es5',
arrowParens: 'always',
};
module.exports = { singleQuote: true };
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,54 @@

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.

## [6.2.0](https://github.com/webpack-contrib/file-loader/compare/v6.1.1...v6.2.0) (2020-10-27)


### Features

* added the `sourceFilename` property to asset info with original filename ([#393](https://github.com/webpack-contrib/file-loader/issues/393)) ([654e0d6](https://github.com/webpack-contrib/file-loader/commit/654e0d641ec067089f6a2d12e30ec3520f00d808))


### Bug Fixes

* immutable flag when the `name` option have hash in query string ([#392](https://github.com/webpack-contrib/file-loader/issues/392)) ([381d8bd](https://github.com/webpack-contrib/file-loader/commit/381d8bda3f2494487bfe840386e365b97b6025fe))

### [6.1.1](https://github.com/webpack-contrib/file-loader/compare/v6.1.0...v6.1.1) (2020-10-09)

### Chore

* update `schema-utils`

## [6.1.0](https://github.com/webpack-contrib/file-loader/compare/v6.0.0...v6.1.0) (2020-08-31)


### Features

* pass immutable flag to asset info ([#383](https://github.com/webpack-contrib/file-loader/issues/383)) ([40fcde8](https://github.com/webpack-contrib/file-loader/commit/40fcde81681d4f8ee19d2ee3845fd34e24459195))

## [6.0.0](https://github.com/webpack-contrib/file-loader/compare/v5.1.0...v6.0.0) (2020-03-17)


### ⚠ BREAKING CHANGES

* use `md4` by default for hashing ([#369](https://github.com/webpack-contrib/file-loader/issues/369)) ([ad39022](https://github.com/webpack-contrib/file-loader/commit/ad3902284d28adeddf667212a39faa4c6bfb2964))

## [5.1.0](https://github.com/webpack-contrib/file-loader/compare/v5.0.2...v5.1.0) (2020-02-19)


### Features

* support the `query` template for the `name` option ([#366](https://github.com/webpack-contrib/file-loader/issues/366)) ([cd8698b](https://github.com/webpack-contrib/file-loader/commit/cd8698b1d9fd560d85e912acca9a1e24f00e18f8))

### [5.0.2](https://github.com/webpack-contrib/file-loader/compare/v5.0.1...v5.0.2) (2019-11-25)


### Chore

* add the `funding` field in `package.json`



### [5.0.1](https://github.com/webpack-contrib/file-loader/compare/v5.0.0...v5.0.1) (2019-11-25)


80 changes: 67 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@

# file-loader

**DEPRECATED for v5**: please consider migrating to [`asset modules`](https://webpack.js.org/guides/asset-modules/).

The `file-loader` resolves `import`/`require()` on a file into a url and emits the file into the output directory.

## Getting Started
@@ -102,7 +104,10 @@ module.exports = {
test: /\.(png|jpe?g|gif)$/i,
loader: 'file-loader',
options: {
name(file) {
name(resourcePath, resourceQuery) {
// `resourcePath` - `/absolute/path/to/file.js`
// `resourceQuery` - `?foo=bar`

if (process.env.NODE_ENV === 'development') {
return '[path][name].[ext]';
}
@@ -184,7 +189,7 @@ module.exports = {
### `publicPath`

Type: `String|Function`
Default: [`__webpack_public_path__`](https://webpack.js.org/api/module-variables/#__webpack_public_path__-webpack-specific-)
Default: [`__webpack_public_path__`](https://webpack.js.org/api/module-variables/#__webpack_public_path__-webpack-specific-)+outputPath

Specifies a custom public path for the target file(s).

@@ -378,12 +383,12 @@ module.exports = {
### `esModule`

Type: `Boolean`
Default: `false`
Default: `true`

By default, `file-loader` generates JS modules that use the ES modules syntax.
There are some cases in which using ES modules is beneficial, like in the case of [module concatenation](https://webpack.js.org/plugins/module-concatenation-plugin/) and [tree shaking](https://webpack.js.org/guides/tree-shaking/).

You can enable a CommonJS module using:
You can enable a CommonJS module syntax using:

**webpack.config.js**

@@ -439,6 +444,13 @@ Default: `file.folder`

The folder of the resource is in.

### `[query]`

Type: `String`
Default: `file.query`

The query of the resource, i.e. `?foo=bar`.

### `[emoji]`

Type: `String`
@@ -456,14 +468,14 @@ Same as above, but with a customizable number of emojis
### `[hash]`

Type: `String`
Default: `md5`
Default: `md4`

Specifies the hash method to use for hashing the file content.

### `[contenthash]`

Type: `String`
Default: `md5`
Default: `md4`

Specifies the hash method to use for hashing the file content.

@@ -485,10 +497,9 @@ base49, base52, base58, base62, base64, and hex.
#### `hashType`

Type: `String`
Default: `'md5'`
Default: `'md4'`

The type of hash that the has function should use. Valid values include: `md5`,
`sha1`, `sha256`, and `sha512`.
The type of hash that the hash function should use. Valid values include: `md4`, `md5`, `sha1`, `sha256`, and `sha512`.

#### `length`

@@ -619,14 +630,55 @@ Result:
path/to/file.png?e43b20c069c4a01867c31e98cbce33c9
```

### CDN

The following examples show how to use `file-loader` for CDN uses query params.

**file.js**

```js
import png from './directory/image.png?width=300&height=300';
```

**webpack.config.js**

```js
module.exports = {
output: {
publicPath: 'https://cdn.example.com/',
},
module: {
rules: [
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext][query]',
},
},
],
},
],
},
};
```

Result:

```bash
# result
https://cdn.example.com/directory/image.png?width=300&height=300
```

### Dynamic public path depending on environment variable at run time

An application might want to configure different CDN hosts depending on an environment variable that is only available when running the application. This can be an advantage, as only one build of the application is necessary, which behaves differntly depending on environment variables of the deployment environment. Since file-loader is applied when compiling the application, and not when running it, the environment variable cannot be used in the file-loader configuration. A way around this is setting the `__webpack_public_path__` to the desired CDN host depending on the environment variable at the entrypoint of the application. The option `postTransformPublicPath` can be used to configure a custom path depending on a variable like `__webpack_public_path__`.
An application might want to configure different CDN hosts depending on an environment variable that is only available when running the application. This can be an advantage, as only one build of the application is necessary, which behaves differently depending on environment variables of the deployment environment. Since file-loader is applied when compiling the application, and not when running it, the environment variable cannot be used in the file-loader configuration. A way around this is setting the `__webpack_public_path__` to the desired CDN host depending on the environment variable at the entrypoint of the application. The option `postTransformPublicPath` can be used to configure a custom path depending on a variable like `__webpack_public_path__`.

**main.js**

```js
const namespace = process.env.NAMESPACE;
const assetPrefixForNamespace = (namespace) => {
switch (namespace) {
case 'prod':
@@ -641,6 +693,8 @@ const assetPrefixForNamespace = (namespace) => {
return '';
}
};
const namespace = process.env.NAMESPACE;

__webpack_public_path__ = `${assetPrefixForNamespace(namespace)}/`;
```

@@ -701,8 +755,8 @@ Please take a moment to read our contributing guidelines if you haven't yet done
[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack-contrib/file-loader.svg
[deps-url]: https://david-dm.org/webpack-contrib/file-loader
[tests]: https://dev.azure.com/webpack-contrib/file-loader/_apis/build/status/webpack-contrib.file-loader?branchName=master
[tests-url]: https://dev.azure.com/webpack-contrib/file-loader/_build/latest?definitionId=2&branchName=master
[tests]: https://github.com/webpack-contrib/file-loader/workflows/file-loader/badge.svg
[tests-url]: https://github.com/webpack-contrib/file-loader/actions
[cover]: https://codecov.io/gh/webpack-contrib/file-loader/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/file-loader
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
200 changes: 0 additions & 200 deletions azure-pipelines.yml

This file was deleted.

4 changes: 2 additions & 2 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
'*.js': ['prettier --write', 'eslint --fix', 'git add'],
'*.{json,md,yml,css,ts}': ['prettier --write', 'git add'],
'*.js': ['prettier --write', 'eslint --fix'],
'*.{json,md,yml,css,ts}': ['prettier --write'],
};
11,113 changes: 6,495 additions & 4,618 deletions package-lock.json

Large diffs are not rendered by default.

57 changes: 29 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "file-loader",
"version": "5.0.1",
"version": "6.2.0",
"description": "A file loader module for webpack",
"license": "MIT",
"repository": "webpack-contrib/file-loader",
"author": "Tobias Koppers @sokra",
"homepage": "https://github.com/webpack-contrib/file-loader",
"bugs": "https://github.com/webpack-contrib/file-loader/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/webpack"
},
"main": "dist/cjs.js",
"engines": {
"node": ">= 10.13.0"
@@ -18,7 +22,7 @@
"build": "cross-env NODE_ENV=production babel src -d dist --copy-files",
"commitlint": "commitlint --from=master",
"security": "npm audit",
"lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different",
"lint:prettier": "prettier --list-different .",
"lint:js": "eslint --cache .",
"lint": "npm-run-all -l -p \"lint:**\"",
"test:only": "cross-env NODE_ENV=test jest",
@@ -37,36 +41,33 @@
"webpack": "^4.0.0 || ^5.0.0"
},
"dependencies": {
"loader-utils": "^1.2.3",
"schema-utils": "^2.5.0"
"loader-utils": "^2.0.0",
"schema-utils": "^3.0.0"
},
"devDependencies": {
"@babel/cli": "^7.7.4",
"@babel/core": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"@webpack-contrib/defaults": "^6.1.0",
"@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": "^24.9.0",
"commitlint-azure-pipelines-cli": "^1.0.2",
"cross-env": "^6.0.3",
"del": "^5.1.0",
"del-cli": "^3.0.0",
"eslint": "^6.7.1",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-import": "^2.18.2",
"husky": "^3.1.0",
"jest": "^24.9.0",
"jest-junit": "^9.0.0",
"lint-staged": "^9.4.3",
"memfs": "^2.16.1",
"memory-fs": "^0.5.0",
"babel-jest": "^26.5.2",
"cross-env": "^7.0.2",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"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": "^1.19.1",
"standard-version": "^7.0.1",
"url-loader": "^2.3.0",
"webpack": "^4.41.2"
"prettier": "^2.1.2",
"standard-version": "^9.0.0",
"url-loader": "^4.1.0",
"webpack": "^4.44.2"
},
"keywords": [
"webpack"
50 changes: 36 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import path from 'path';

import loaderUtils from 'loader-utils';
import validateOptions from 'schema-utils';
import { getOptions, interpolateName } from 'loader-utils';
import { validate } from 'schema-utils';

import schema from './options.json';
import { normalizePath } from './utils';

export default function loader(content) {
const options = loaderUtils.getOptions(this) || {};
const options = getOptions(this);

validateOptions(schema, options, {
validate(schema, options, {
name: 'File Loader',
baseDataPath: 'options',
});

const context = options.context || this.rootContext;
const name = options.name || '[contenthash].[ext]';

const url = loaderUtils.interpolateName(
this,
options.name || '[contenthash].[ext]',
{
context,
content,
regExp: options.regExp,
}
);
const url = interpolateName(this, name, {
context,
content,
regExp: options.regExp,
});

let outputPath = url;

@@ -56,7 +54,31 @@ export default function loader(content) {
}

if (typeof options.emitFile === 'undefined' || options.emitFile) {
this.emitFile(outputPath, content);
const assetInfo = {};

if (typeof name === 'string') {
let normalizedName = name;

const idx = normalizedName.indexOf('?');

if (idx >= 0) {
normalizedName = normalizedName.substr(0, idx);
}

const isImmutable = /\[([^:\]]+:)?(hash|contenthash)(:[^\]]+)?]/gi.test(
normalizedName
);

if (isImmutable === true) {
assetInfo.immutable = true;
}
}

assetInfo.sourceFilename = normalizePath(
path.relative(this.rootContext, this.resourcePath)
);

this.emitFile(outputPath, content, null, assetInfo);
}

const esModule =
1 change: 1 addition & 0 deletions src/options.json
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@
]
},
"esModule": {
"description": "By default, file-loader generates JS modules that use the ES modules syntax.",
"type": "boolean"
}
},
38 changes: 38 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function normalizePath(path, stripTrailing) {
if (path === '\\' || path === '/') {
return '/';
}

const len = path.length;

if (len <= 1) {
return path;
}

// ensure that win32 namespaces has two leading slashes, so that the path is
// handled properly by the win32 version of path.parse() after being normalized
// https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
let prefix = '';

if (len > 4 && path[3] === '\\') {
// eslint-disable-next-line prefer-destructuring
const ch = path[2];

if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') {
// eslint-disable-next-line no-param-reassign
path = path.slice(2);
prefix = '//';
}
}

const segs = path.split(/[/\\]+/);

if (stripTrailing !== false && segs[segs.length - 1] === '') {
segs.pop();
}

return prefix + segs.join('/');
}

// eslint-disable-next-line import/prefer-default-export
export { normalizePath };
10 changes: 5 additions & 5 deletions test/__snapshots__/emitFile-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -8,32 +8,32 @@ Array [

exports[`"emitFile" option should work with "Boolean" value equal "false": errors 1`] = `Array []`;

exports[`"emitFile" option should work with "Boolean" value equal "false": result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"emitFile" option should work with "Boolean" value equal "false": result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"emitFile" option should work with "Boolean" value equal "false": warnings 1`] = `Array []`;

exports[`"emitFile" option should work with "Boolean" value equal "true": assets 1`] = `
Array [
"9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`"emitFile" option should work with "Boolean" value equal "true": errors 1`] = `Array []`;

exports[`"emitFile" option should work with "Boolean" value equal "true": result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"emitFile" option should work with "Boolean" value equal "true": result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"emitFile" option should work with "Boolean" value equal "true": warnings 1`] = `Array []`;

exports[`"emitFile" option should work without value: assets 1`] = `
Array [
"9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`"emitFile" option should work without value: errors 1`] = `Array []`;

exports[`"emitFile" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"emitFile" option should work without value: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"emitFile" option should work without value: warnings 1`] = `Array []`;
6 changes: 3 additions & 3 deletions test/__snapshots__/esModule-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -2,18 +2,18 @@

exports[`"esModule" option should work with "Boolean" value equal "false": errors 1`] = `Array []`;

exports[`"esModule" option should work with "Boolean" value equal "false": result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"esModule" option should work with "Boolean" value equal "false": result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"esModule" option should work with "Boolean" value equal "false": warnings 1`] = `Array []`;

exports[`"esModule" option should work with "Boolean" value equal "true": errors 1`] = `Array []`;

exports[`"esModule" option should work with "Boolean" value equal "true": result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"esModule" option should work with "Boolean" value equal "true": result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"esModule" option should work with "Boolean" value equal "true": warnings 1`] = `Array []`;

exports[`"esModule" option should work without value: errors 1`] = `Array []`;

exports[`"esModule" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"esModule" option should work without value: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"esModule" option should work without value: warnings 1`] = `Array []`;
12 changes: 6 additions & 6 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
@@ -2,27 +2,27 @@

exports[`loader should work with "ModuleConcatenationPlugin" plugin: assets 1`] = `
Array [
"9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`loader should work with "ModuleConcatenationPlugin" plugin: errors 1`] = `Array []`;

exports[`loader should work with "ModuleConcatenationPlugin" plugin: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`loader should work with "ModuleConcatenationPlugin" plugin: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`loader should work with "ModuleConcatenationPlugin" plugin: warnings 1`] = `Array []`;

exports[`loader should work with "url-loader" when limit is less: assets 1`] = `
Array [
"9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`loader should work with "url-loader" when limit is less: errors 1`] = `Array []`;

exports[`loader should work with "url-loader" when limit is less: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`loader should work with "url-loader" when limit is less: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`loader should work with "url-loader" when limit is less: warnings 1`] = `Array []`;

@@ -40,13 +40,13 @@ exports[`loader should works with "url-loader" when limit is more: warnings 1`]

exports[`loader should works without options: assets 1`] = `
Array [
"9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`loader should works without options: errors 1`] = `Array []`;

exports[`loader should works without options: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`loader should works without options: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`loader should works without options: warnings 1`] = `Array []`;
12 changes: 9 additions & 3 deletions test/__snapshots__/name-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"name" option should work for CDN support query params: errors 1`] = `Array []`;

exports[`"name" option should work for CDN support query params: result 1`] = `"https://cdn.example.com/nested/file.png?foo=bar"`;

exports[`"name" option should work for CDN support query params: warnings 1`] = `Array []`;

exports[`"name" option should work with "Function" value: errors 1`] = `Array []`;

exports[`"name" option should work with "Function" value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.function.png"`;
exports[`"name" option should work with "Function" value: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.function.png?foo=bar"`;

exports[`"name" option should work with "Function" value: warnings 1`] = `Array []`;

exports[`"name" option should work with "String" value: errors 1`] = `Array []`;

exports[`"name" option should work with "String" value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.string.png"`;
exports[`"name" option should work with "String" value: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.string.png?foo=bar"`;

exports[`"name" option should work with "String" value: warnings 1`] = `Array []`;

exports[`"name" option should work without value: errors 1`] = `Array []`;

exports[`"name" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"name" option should work without value: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"name" option should work without value: warnings 1`] = `Array []`;
36 changes: 18 additions & 18 deletions test/__snapshots__/outputPath-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -15,40 +15,40 @@ exports[`"outputPath" option should work with "Function" value and with "name" o

exports[`"outputPath" option should work with "Function" value and with "publicPath" as "Function": assets 1`] = `
Array [
"output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"output_path_func/39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`"outputPath" option should work with "Function" value and with "publicPath" as "Function": errors 1`] = `Array []`;

exports[`"outputPath" option should work with "Function" value and with "publicPath" as "Function": result 1`] = `"public_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"outputPath" option should work with "Function" value and with "publicPath" as "Function": result 1`] = `"public_path_func/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"outputPath" option should work with "Function" value and with "publicPath" as "Function": warnings 1`] = `Array []`;

exports[`"outputPath" option should work with "Function" value and with "publicPath" as "String": assets 1`] = `
Array [
"output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"output_path_func/39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`"outputPath" option should work with "Function" value and with "publicPath" as "String": errors 1`] = `Array []`;

exports[`"outputPath" option should work with "Function" value and with "publicPath" as "String": result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"outputPath" option should work with "Function" value and with "publicPath" as "String": result 1`] = `"public_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"outputPath" option should work with "Function" value and with "publicPath" as "String": warnings 1`] = `Array []`;

exports[`"outputPath" option should work with "Function" value: assets 1`] = `
Array [
"output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"output_path_func/39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`"outputPath" option should work with "Function" value: errors 1`] = `Array []`;

exports[`"outputPath" option should work with "Function" value: result 1`] = `"output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"outputPath" option should work with "Function" value: result 1`] = `"output_path_func/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"outputPath" option should work with "Function" value: warnings 1`] = `Array []`;

@@ -67,78 +67,78 @@ exports[`"outputPath" option should work with "String" value and with "name" opt

exports[`"outputPath" option should work with "String" value and with "publicPath" as "Function": assets 1`] = `
Array [
"output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"output_path/39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`"outputPath" option should work with "String" value and with "publicPath" as "Function": errors 1`] = `Array []`;

exports[`"outputPath" option should work with "String" value and with "publicPath" as "Function": result 1`] = `"public_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"outputPath" option should work with "String" value and with "publicPath" as "Function": result 1`] = `"public_path_func/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"outputPath" option should work with "String" value and with "publicPath" as "Function": warnings 1`] = `Array []`;

exports[`"outputPath" option should work with "String" value and with "publicPath" option and without trailing slash: assets 1`] = `
Array [
"output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"output_path/39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`"outputPath" option should work with "String" value and with "publicPath" option and without trailing slash: errors 1`] = `Array []`;

exports[`"outputPath" option should work with "String" value and with "publicPath" option and without trailing slash: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"outputPath" option should work with "String" value and with "publicPath" option and without trailing slash: result 1`] = `"public_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"outputPath" option should work with "String" value and with "publicPath" option and without trailing slash: warnings 1`] = `Array []`;

exports[`"outputPath" option should work with "String" value and with "publicPath" option: assets 1`] = `
Array [
"output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"output_path/39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`"outputPath" option should work with "String" value and with "publicPath" option: errors 1`] = `Array []`;

exports[`"outputPath" option should work with "String" value and with "publicPath" option: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"outputPath" option should work with "String" value and with "publicPath" option: result 1`] = `"public_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"outputPath" option should work with "String" value and with "publicPath" option: warnings 1`] = `Array []`;

exports[`"outputPath" option should work with "String" value without trailing slash: assets 1`] = `
Array [
"output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"output_path/39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`"outputPath" option should work with "String" value without trailing slash: errors 1`] = `Array []`;

exports[`"outputPath" option should work with "String" value without trailing slash: result 1`] = `"output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"outputPath" option should work with "String" value without trailing slash: result 1`] = `"output_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"outputPath" option should work with "String" value without trailing slash: warnings 1`] = `Array []`;

exports[`"outputPath" option should work with "String" value: assets 1`] = `
Array [
"output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"output_path/39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`"outputPath" option should work with "String" value: errors 1`] = `Array []`;

exports[`"outputPath" option should work with "String" value: result 1`] = `"output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"outputPath" option should work with "String" value: result 1`] = `"output_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"outputPath" option should work with "String" value: warnings 1`] = `Array []`;

exports[`"outputPath" option should work without value: assets 1`] = `
Array [
"9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
"39f5c21c1aee6ff21844c6e1d8251d97.png",
"main.bundle.js",
]
`;

exports[`"outputPath" option should work without value: errors 1`] = `Array []`;

exports[`"outputPath" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"outputPath" option should work without value: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"outputPath" option should work without value: warnings 1`] = `Array []`;
18 changes: 9 additions & 9 deletions test/__snapshots__/postTransformPublicPath-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -2,54 +2,54 @@

exports[`"postTransformPublicPath" option should work with "Function" and "publicPath" option as "Function": errors 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" and "publicPath" option as "Function": result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"postTransformPublicPath" option should work with "Function" and "publicPath" option as "Function": result 1`] = `"public_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"postTransformPublicPath" option should work with "Function" and "publicPath" option as "Function": warnings 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and "publicPath" option as "Function": errors 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and "publicPath" option as "Function": result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png?test=test"`;
exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and "publicPath" option as "Function": result 1`] = `"public_path/39f5c21c1aee6ff21844c6e1d8251d97.png?test=test"`;

exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and "publicPath" option as "Function": warnings 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and use "publicPath" option: errors 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and use "publicPath" option: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png?test=test"`;
exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and use "publicPath" option: result 1`] = `"public_path/39f5c21c1aee6ff21844c6e1d8251d97.png?test=test"`;

exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and use "publicPath" option: warnings 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value: errors 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png/test"`;
exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png/test"`;

exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value: warnings 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where prepend "__webpack_public_path__" and "publicPath" option as "String": errors 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where prepend "__webpack_public_path__" and "publicPath" option as "String": result 1`] = `"http://code.com/public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"postTransformPublicPath" option should work with "Function" where prepend "__webpack_public_path__" and "publicPath" option as "String": result 1`] = `"http://code.com/public_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"postTransformPublicPath" option should work with "Function" where prepend "__webpack_public_path__" and "publicPath" option as "String": warnings 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where prepend path and "publicPath" option as "String": errors 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where prepend path and "publicPath" option as "String": result 1`] = `"path_prefix/public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"postTransformPublicPath" option should work with "Function" where prepend path and "publicPath" option as "String": result 1`] = `"path_prefix/public_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"postTransformPublicPath" option should work with "Function" where prepend path and "publicPath" option as "String": warnings 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification and use "publicPath" option: errors 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification and use "publicPath" option: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification and use "publicPath" option: result 1`] = `"public_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification and use "publicPath" option: warnings 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification: errors 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification: warnings 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work without value: errors 1`] = `Array []`;

exports[`"postTransformPublicPath" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"postTransformPublicPath" option should work without value: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"postTransformPublicPath" option should work without value: warnings 1`] = `Array []`;
10 changes: 5 additions & 5 deletions test/__snapshots__/publicPath-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -2,30 +2,30 @@

exports[`"publicPath" option should work with "Function" value and pass "url", "resourcePath" and "context" as arguments: errors 1`] = `Array []`;

exports[`"publicPath" option should work with "Function" value and pass "url", "resourcePath" and "context" as arguments: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"publicPath" option should work with "Function" value and pass "url", "resourcePath" and "context" as arguments: result 1`] = `"public_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"publicPath" option should work with "Function" value and pass "url", "resourcePath" and "context" as arguments: warnings 1`] = `Array []`;

exports[`"publicPath" option should work with "String" value equal an URL: errors 1`] = `Array []`;

exports[`"publicPath" option should work with "String" value equal an URL: result 1`] = `"https://cdn.com/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"publicPath" option should work with "String" value equal an URL: result 1`] = `"https://cdn.com/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"publicPath" option should work with "String" value equal an URL: warnings 1`] = `Array []`;

exports[`"publicPath" option should work with "String" value without trailing slash: errors 1`] = `Array []`;

exports[`"publicPath" option should work with "String" value without trailing slash: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"publicPath" option should work with "String" value without trailing slash: result 1`] = `"public_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"publicPath" option should work with "String" value without trailing slash: warnings 1`] = `Array []`;

exports[`"publicPath" option should work with "String" value: errors 1`] = `Array []`;

exports[`"publicPath" option should work with "String" value: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"publicPath" option should work with "String" value: result 1`] = `"public_path/39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"publicPath" option should work with "String" value: warnings 1`] = `Array []`;

exports[`"publicPath" option should work without value: errors 1`] = `Array []`;

exports[`"publicPath" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;
exports[`"publicPath" option should work without value: result 1`] = `"39f5c21c1aee6ff21844c6e1d8251d97.png"`;

exports[`"publicPath" option should work without value: warnings 1`] = `Array []`;
17 changes: 9 additions & 8 deletions test/__snapshots__/validate-options.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`validate options should throw an error on the "context" option with "true" value 1`] = `
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema.
"Invalid options object. File Loader has been initialized using an options object that does not match the API schema.
- options.context should be a string.
-> A custom file context (https://github.com/webpack-contrib/file-loader#context)."
`;

exports[`validate options should throw an error on the "emitFile" option with "true" value 1`] = `
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema.
"Invalid options object. File Loader has been initialized using an options object that does not match the API schema.
- options.emitFile should be a boolean.
-> Enables/Disables emit files (https://github.com/webpack-contrib/file-loader#emitfile)."
`;

exports[`validate options should throw an error on the "esModule" option with "true" value 1`] = `
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema.
- options.esModule should be a boolean."
"Invalid options object. File Loader has been initialized using an options object that does not match the API schema.
- options.esModule should be a boolean.
-> By default, file-loader generates JS modules that use the ES modules syntax."
`;

exports[`validate options should throw an error on the "name" option with "true" value 1`] = `
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema.
"Invalid options object. File Loader has been initialized using an options object that does not match the API schema.
- options.name should be one of these:
string | function
-> The filename template for the target file(s) (https://github.com/webpack-contrib/file-loader#name).
@@ -28,7 +29,7 @@ exports[`validate options should throw an error on the "name" option with "true"
`;

exports[`validate options should throw an error on the "outputPath" option with "true" value 1`] = `
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema.
"Invalid options object. File Loader has been initialized using an options object that does not match the API schema.
- options.outputPath should be one of these:
string | function
-> A filesystem path where the target file(s) will be placed (https://github.com/webpack-contrib/file-loader#outputpath).
@@ -38,7 +39,7 @@ exports[`validate options should throw an error on the "outputPath" option with
`;

exports[`validate options should throw an error on the "publicPath" option with "true" value 1`] = `
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema.
"Invalid options object. File Loader has been initialized using an options object that does not match the API schema.
- options.publicPath should be one of these:
string | function
-> A custom public path for the target file(s) (https://github.com/webpack-contrib/file-loader#publicpath).
@@ -48,7 +49,7 @@ exports[`validate options should throw an error on the "publicPath" option with
`;

exports[`validate options should throw an error on the "regExp" option with "true" value 1`] = `
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema.
"Invalid options object. File Loader has been initialized using an options object that does not match the API schema.
- options.regExp should be one of these:
string | RegExp
-> A Regular Expression to one or many parts of the target file path. The capture groups can be reused in the name property using [N] placeholder (https://github.com/webpack-contrib/file-loader#regexp).
6 changes: 6 additions & 0 deletions test/fixtures/cdn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable */
import png from './nested/file.png?foo=bar#hash';

__export__ = png;

export default png;
Binary file added test/fixtures/nested/file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/fixtures/simple.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import png from './file.png';
import png from './file.png?foo=bar';

__export__ = png;

1 change: 1 addition & 0 deletions test/helpers/getCompiler.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ export default (fixture, loaderOptions = {}, config = {}) => {
context: path.resolve(__dirname, '../fixtures'),
entry: path.resolve(__dirname, '../fixtures', fixture),
output: {
publicPath: '',
path: path.resolve(__dirname, '../outputs'),
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js',
8 changes: 1 addition & 7 deletions test/helpers/normalizeErrors.js
Original file line number Diff line number Diff line change
@@ -14,12 +14,6 @@ function removeCWD(str) {

export default (errors) => {
return errors.map((error) =>
removeCWD(
error
.toString()
.split('\n')
.slice(0, 2)
.join('\n')
)
removeCWD(error.toString().split('\n').slice(0, 2).join('\n'))
);
};
2 changes: 1 addition & 1 deletion test/loader.test.js
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ describe('loader', () => {
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors');

if (stats.compilation.modules.size) {
expect(stats.compilation.modules.size).toBe(2);
expect(stats.compilation.modules.size).toBe(3);
} else {
expect(stats.compilation.modules.length).toBe(1);
}
155 changes: 152 additions & 3 deletions test/name-option.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from 'path';

import {
compile,
execute,
@@ -22,7 +24,7 @@ describe('"name" option', () => {

it('should work with "String" value', async () => {
const compiler = getCompiler('simple.js', {
name: '[hash].string.[ext]',
name: '[hash].string.[ext][query]',
});
const stats = await compile(compiler);

@@ -37,8 +39,11 @@ describe('"name" option', () => {

it('should work with "Function" value', async () => {
const compiler = getCompiler('simple.js', {
name() {
return '[hash].function.[ext]';
name(resourcePath, resourceQuery) {
expect(resourcePath).toBeDefined();
expect(resourceQuery).toBeDefined();

return '[hash].function.[ext][query]';
},
});
const stats = await compile(compiler);
@@ -51,4 +56,148 @@ describe('"name" option', () => {
);
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors');
});

it('should work for CDN support query params', async () => {
const compiler = getCompiler(
'cdn.js',
{
name: '[path][name].[ext][query]',
},
{
output: {
path: path.resolve(__dirname, './outputs'),
publicPath: 'https://cdn.example.com/',
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js',
},
}
);
const stats = await compile(compiler);

expect(
execute(readAsset('main.bundle.js', compiler, stats))
).toMatchSnapshot('result');
expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot(
'warnings'
);
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors');
});

it('should work and emit "immutable" for assets flag by default', async () => {
expect.assertions(1);

const compiler = getCompiler('simple.js');
const stats = await compile(compiler);

for (const [name, info] of stats.compilation.assetsInfo) {
if (name.endsWith('.png')) {
expect(info.immutable).toBe(true);
}
}
});

it('should work and emit "immutable" for hashed assets', async () => {
expect.assertions(1);

const compiler = getCompiler('simple.js', {
name: '[md5:hash:hex:8].asset.[ext]',
});
const stats = await compile(compiler);

for (const [name, info] of stats.compilation.assetsInfo) {
if (name.endsWith('.png')) {
expect(info.immutable).toBe(true);
}
}
});

it('should work and emit "immutable" for hashed assets #2', async () => {
expect.assertions(1);

const compiler = getCompiler('simple.js', {
name: '[name].[contenthash].asset.[ext]',
});
const stats = await compile(compiler);

for (const [name, info] of stats.compilation.assetsInfo) {
if (name.startsWith('file.39f5c21c1aee6ff21844c6e1d8251d97.asset.png')) {
expect(info.immutable).toBe(true);
}
}
});

it('should work and emit "immutable" for hashed assets #3', async () => {
expect.assertions(1);

const compiler = getCompiler('simple.js', {
name: '[name].asset.[ext]?foo=[contenthash]',
});
const stats = await compile(compiler);

for (const [name, info] of stats.compilation.assetsInfo) {
if (name.startsWith('file.asset.png')) {
// eslint-disable-next-line no-undefined
expect(info.immutable).toBe(undefined);
}
}
});

it('should work and not emit "immutable" for not hashed assets', async () => {
expect.assertions(1);

const compiler = getCompiler('simple.js', {
name: 'asset.[ext]',
});
const stats = await compile(compiler);

for (const [name, info] of stats.compilation.assetsInfo) {
if (name.startsWith('asset.png')) {
// eslint-disable-next-line no-undefined
expect(info.immutable).toBe(undefined);
}
}
});

it('should work and add "sourceFilename" to asset info', async () => {
expect.assertions(1);

const compiler = getCompiler('simple.js');
const stats = await compile(compiler);

for (const [name, info] of stats.compilation.assetsInfo) {
if (name.endsWith('.png')) {
expect(info.sourceFilename).toBe('file.png');
}
}
});

it('should work and add "sourceFilename" to asset info #2', async () => {
expect.assertions(1);

const compiler = getCompiler('simple.js', {
name: '[name].asset.[ext]?foo=[contenthash]',
});
const stats = await compile(compiler);

for (const [name, info] of stats.compilation.assetsInfo) {
if (name.startsWith('file.asset.png')) {
expect(info.sourceFilename).toBe('file.png');
}
}
});

it('should work and add "sourceFilename" to asset info #3', async () => {
expect.assertions(1);

const compiler = getCompiler('cdn.js', {
name: '[name].asset.[ext]',
});
const stats = await compile(compiler);

for (const [name, info] of stats.compilation.assetsInfo) {
if (name.startsWith('file.asset.png')) {
expect(info.sourceFilename).toBe('nested/file.png');
}
}
});
});
9 changes: 5 additions & 4 deletions test/outputPath-option.test.js
Original file line number Diff line number Diff line change
@@ -71,12 +71,13 @@ describe('"outputPath" option', () => {
});

it('should work with "Function" value', async () => {
// TODO
expect.assertions(7);

const compiler = getCompiler('simple.js', {
outputPath(url, resourcePath, context) {
expect(url).toBe('9c87cbf3ba33126ffd25ae7f2f6bbafb.png');
expect(resourcePath).toMatch('file.png');
expect(context).toMatch('fixtures');
expect(typeof url).toBe('string');
expect(typeof resourcePath).toBe('string');
expect(typeof context).toBe('string');

return `output_path_func/${url}`;
},
6 changes: 3 additions & 3 deletions test/publicPath-option.test.js
Original file line number Diff line number Diff line change
@@ -70,9 +70,9 @@ describe('"publicPath" option', () => {

const compiler = getCompiler('simple.js', {
publicPath(url, resourcePath, context) {
expect(url).toMatch('9c87cbf3ba33126ffd25ae7f2f6bbafb.png');
expect(resourcePath).toMatch('file.png');
expect(context).toMatch('fixtures');
expect(typeof url).toBe('string');
expect(typeof resourcePath).toBe('string');
expect(typeof context).toBe('string');

return `public_path/${url}`;
},