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/url-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 672ba8078ad0879d13248929876de157ac59a06f
Choose a base ref
...
head repository: webpack-contrib/url-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0eeaaa93d574b98ba405c17947a3f0ffbea5583b
Choose a head ref
  • 11 commits
  • 37 files changed
  • 3 contributors

Commits on Dec 17, 2017

  1. refactor: apply webpack-defaults (#102)

    - Upgrades to `webpack-defaults@2.0.0`
    - Drops support for `node =< v4.0.0`
    - Sets the minimum `peerDependency` to `webpack >= 3.0.0`
    
    BREAKING CHANGE: Sets `engines` to `"node": ">= 6.9.0 || >= 8.9.0"`
    BREAKING CHANGE: Drops support for `webpack =< v2.0.0`
    michael-ciniawsky authored and joshwiens committed Dec 17, 2017
    Copy the full SHA
    073b588 View commit details
  2. Copy the full SHA
    5ce17f7 View commit details
  3. Copy the full SHA
    f9174d2 View commit details
  4. Copy the full SHA
    b61859c View commit details
  5. Copy the full SHA
    3c87902 View commit details

Commits on Dec 20, 2017

  1. Copy the full SHA
    5aeba3e View commit details
  2. Copy the full SHA
    4a62cd5 View commit details
  3. Copy the full SHA
    b4be0c8 View commit details

Commits on Mar 3, 2018

  1. Copy the full SHA
    457618b View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0390cdb View commit details
  3. Copy the full SHA
    0eeaaa9 View commit details
35 changes: 35 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"presets": [
[
"env",
{
"useBuiltIns": true,
"targets": {
"node": "6.9.0"
},
"exclude": [
"transform-async-to-generator",
"transform-regenerator"
]
}
]
],
"plugins": [
[
"transform-object-rest-spread",
{
"useBuiltIns": true
}
]
],
"env": {
"test": {
"presets": [
"env"
],
"plugins": [
"transform-object-rest-spread"
]
}
}
}
161 changes: 161 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
unit_tests: &unit_tests
steps:
- checkout
- setup_remote_docker
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: NPM Rebuild
command: npm install
- run:
name: Run unit tests.
command: npm run ci:test
canary_tests: &canary_tests
steps:
- checkout
- setup_remote_docker
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: NPM Rebuild
command: npm install
- run:
name: Install Webpack Canary
command: npm i --no-save webpack@next
- run:
name: Run unit tests.
command: npm run ci:test

version: 2
jobs:
dependency_cache:
docker:
- image: webpackcontrib/circleci-node-base:latest
steps:
- checkout
- setup_remote_docker
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: Install Dependencies
command: npm install
- save_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
paths:
- ./node_modules

node8-latest:
docker:
- image: webpackcontrib/circleci-node8:latest
steps:
- checkout
- setup_remote_docker
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: NPM Rebuild
command: npm install
- run:
name: Run unit tests.
command: npm run ci:coverage
- run:
name: Submit coverage data to codecov.
command: bash <(curl -s https://codecov.io/bash)
when: on_success
node6-latest:
docker:
- image: webpackcontrib/circleci-node6:latest
<<: *unit_tests
node9-latest:
docker:
- image: webpackcontrib/circleci-node9:latest
<<: *unit_tests
node8-canary:
docker:
- image: webpackcontrib/circleci-node8:latest
<<: *canary_tests
analysis:
docker:
- image: webpackcontrib/circleci-node-base:latest
steps:
- checkout
- setup_remote_docker
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: NPM Rebuild
command: npm install
- run:
name: Run linting.
command: npm run lint
- run:
name: Run NSP Security Check.
command: npm run security
- run:
name: Validate Commit Messages
command: npm run ci:lint:commits
publish:
docker:
- image: webpackcontrib/circleci-node-base:latest
steps:
- checkout
- setup_remote_docker
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: NPM Rebuild
command: npm install
- run:
name: Validate Commit Messages
command: npm run release:validate
- run:
name: Publish to NPM
command: printf "noop running conventional-github-releaser"

version: 2.0
workflows:
version: 2
validate-publish:
jobs:
- dependency_cache
- node6-latest:
requires:
- dependency_cache
filters:
tags:
only: /.*/
- analysis:
requires:
- dependency_cache
filters:
tags:
only: /.*/
- node8-latest:
requires:
- analysis
- node6-latest
filters:
tags:
only: /.*/
- node9-latest:
requires:
- analysis
- node6-latest
filters:
tags:
only: /.*/
- node8-canary:
requires:
- analysis
- node6-latest
filters:
tags:
only: /.*/
- publish:
requires:
- node8-latest
- node9-latest
filters:
branches:
only:
- master
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[.md]
insert_final_newline = false
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/dist
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
root: true,
plugins: ['prettier'],
extends: ['@webpack-contrib/eslint-config-webpack'],
rules: {
'prettier/prettier': [
'error',
{ singleQuote: true, trailingComma: 'es5', arrowParens: 'always' },
],
},
};
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package-lock.json -diff
* text=auto
bin/* eol=lf
6 changes: 6 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# These are the default owners for everything in
# webpack-contrib
@webpack-contrib/org-maintainers

# Add repository specific users / groups
# below here for libs that are not maintained by the org.
20 changes: 6 additions & 14 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
<!-- Before creating an issue please make sure you are using the latest version of url-loader. -->
<!--
1. Check the version of package you are using. If it's not the newest version, update and try again (see changelog while updating!).
2. If the issue is still there, write a minimal project showing the problem and expected output.
3. Link to the project and mention Node version and OS in your report.
**Do you want to request a *feature* or report a *bug*?**
<!-- Please ask questions on StackOverflow or the webpack Gitter (https://gitter.im/webpack/webpack). Questions will be closed. -->

**What is the current behavior?**

**If the current behavior is a bug, please provide the steps to reproduce.**
<!-- A great way to do this is to provide your configuration via a GitHub gist. -->

**What is the expected behavior?**

**If this is a feature request, what is motivation or use case for changing the behavior?**

**Please mention other relevant information such as your webpack version, Node.js version and Operating System.**
**IMPORTANT! You should use [Stack Overflow](https://stackoverflow.com/) for support related questions.**
-->
23 changes: 5 additions & 18 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. -->

**What kind of change does this PR introduce?**
<!-- E.g. a bugfix, feature, refactoring, build related change, etc… -->

**Did you add tests for your changes?**

**If relevant, did you update the README?**

**Summary**

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
<!-- Try to link to an open issue for more information. -->

**Does this PR introduce a breaking change?**
<!-- If this PR introduces a breaking change, please describe the impact and a migration path for existing applications. -->

**Other information**
<!--
1. [Read and sign the CLA](https://cla.js.foundation/webpack/webpack.js.org). This needs to be done only once. PRs that haven't signed it won't be accepted.
2. Check out the [development guide](https://webpack.js.org/development/) for the API and development guidelines.
3. Read through the PR diff carefully as sometimes this can reveal issues. The work will be reviewed, but this can save some effort.
-->
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
node_modules
node_modules
logs
*.log
npm-debug.log*
.eslintcache
/coverage
/dist
/local
/reports
/node_modules
.DS_Store
Thumbs.db
.idea
.vscode
*.sublime-project
*.sublime-workspace
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,32 @@

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.

<a name="1.0.0"></a>
# [1.0.0](https://github.com/webpack-contrib/url-loader/compare/v1.0.0-beta.0...v1.0.0) (2018-03-03)


### Bug Fixes

* **index:** use `Buffer.from` instead of deprecated `new Buffer` ([#113](https://github.com/webpack-contrib/url-loader/issues/113)) ([457618b](https://github.com/webpack-contrib/url-loader/commit/457618b))



<a name="1.0.0-beta.0"></a>
# [1.0.0-beta.0](https://github.com/webpack-contrib/url-loader/compare/v0.6.2...v1.0.0-beta.0) (2017-12-17)


### Code Refactoring

* apply `webpack-defaults` ([#102](https://github.com/webpack-contrib/url-loader/issues/102)) ([073b588](https://github.com/webpack-contrib/url-loader/commit/073b588))


### BREAKING CHANGES

* Sets `engines` to `"node": ">= 6.9.0 || >= 8.9.0"`
* Drops support for `webpack =< v2.0.0`



<a name="0.6.2"></a>
## [0.6.2](https://github.com/webpack-contrib/url-loader/compare/v0.6.1...v0.6.2) (2017-10-04)

322 changes: 157 additions & 165 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,165 +1,157 @@
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]

<div align="center">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200"
src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg">
</a>
<h1>URL Loader</h1>
<p>Loads files as `base64` encoded URL</p>
</div>

<h2 align="center">Install</h2>

```bash
npm install --save-dev url-loader
```

<h2 align="center"><a href="https://webpack.js.org/concepts/loaders">Usage</a></h2>

The `url-loader` works like the [`file-loader`](https://github.com/webpack-contrib/file-loader), but can return a DataURL if the file is smaller than a byte limit.


```js
import img from './image.png'
```

**webpack.config.js**
```js
module.exports = {
module: {
rules: [
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192
}
}
]
}
]
}
}
```

<h2 align="center">Options</h2>

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**`limit`**|`{Number}`|`undefined`|Byte limit to inline files as Data URL|
|**`mimetype`**|`{String}`|`extname`|Specify MIME type for the file (Otherwise it's inferred from the file extension)|
|**`fallback`**|`{String}`|`file-loader`|Specify `loader` for the file when file is greater than the limit (in bytes)|

### `limit`

If the file is greater than the limit (in bytes) the [`file-loader`](https://github.com/webpack-contrib/file-loader) is used by default and all query parameters are passed to it.
You can use other loader using `fallback` option.

The limit can be specified via loader options and defaults to no limit.

**webpack.config.js**
```js
{
loader: 'url-loader',
options: {
limit: 8192
}
}
```

### `mimetype`

Set the MIME type for the file. If unspecified the file extensions will be used to lookup the MIME type.

**webpack.config.js**
```js
{
loader: 'url-loader',
options: {
mimetype: 'image/png'
}
}
```

### `fallback`

**webpack.config.js**
```js
{
loader: 'url-loader',
options: {
fallback: 'responsive-loader'
}
}
```

<h2 align="center">Maintainers</h2>

<table>
<tbody>
<tr>
<td align="center">
<a href="https://github.com/bebraw">
<img width="150" height="150" src="https://github.com/bebraw.png?v=3&s=150">
</br>
Juho Vepsäläinen
</a>
</td>
<td align="center">
<a href="https://github.com/d3viant0ne">
<img width="150" height="150" src="https://github.com/d3viant0ne.png?v=3&s=150">
</br>
Joshua Wiens
</a>
</td>
<td align="center">
<a href="https://github.com/sapegin">
<img width="150" height="150" src="https://github.com/sapegin.png?v=3&s=150">
</br>
Artem Sapegin
</a>
</td>
<td align="center">
<a href="https://github.com/michael-ciniawsky">
<img width="150" height="150" src="https://github.com/michael-ciniawsky.png?v=3&s=150">
</br>
Michael Ciniawsky
</a>
</td>
<td align="center">
<a href="https://github.com/evilebottnawi">
<img width="150" height="150" src="https://github.com/evilebottnawi.png?v=3&s=150">
</br>
Alexander Krasnoyarov
</a>
</td>
</tr>
<tbody>
</table>


[npm]: https://img.shields.io/npm/v/url-loader.svg
[npm-url]: https://npmjs.com/package/url-loader

[node]: https://img.shields.io/node/v/url-loader.svg
[node-url]: https://nodejs.org

[deps]: https://david-dm.org/webpack-contrib/url-loader.svg
[deps-url]: https://david-dm.org/webpack-contrib/url-loader

[tests]: http://img.shields.io/travis/webpack-contrib/url-loader.svg
[tests-url]: https://travis-ci.org/webpack-contrib/url-loader

[cover]: https://coveralls.io/repos/github/webpack-contrib/url-loader/badge.svg
[cover-url]: https://coveralls.io/github/webpack-contrib/url-loader

[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![npm][npm]][npm-url]
[![chat][chat]][chat-url]

<div align="center">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200"
src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg">
</a>
<h1>URL Loader</h1>
<p>Loads files as `base64` encoded URL</p>
</div>

<h2 align="center">Install</h2>

```bash
npm install --save-dev url-loader
```

<h2 align="center"><a href="https://webpack.js.org/concepts/loaders">Usage</a></h2>

The `url-loader` works like the [`file-loader`](https://github.com/webpack-contrib/file-loader), but can return a DataURL if the file is smaller than a byte limit.


```js
import img from './image.png'
```

**webpack.config.js**
```js
module.exports = {
module: {
rules: [
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192
}
}
]
}
]
}
}
```

<h2 align="center">Options</h2>

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**[`limit`](#limit)**|`{Number}`|`undefined`|Byte limit to inline files as Data URL|
|**[`mimetype`](#mimetype)**|`{String}`|`extname`|Specify MIME type for the file (Otherwise it's inferred from the file extension)|
|**[`fallback`](#fallback)**|`{String}`|`file-loader`|Specify `loader` for the file when file is greater than the limit (in bytes)|

### `limit`

If the file is greater than the limit (in bytes) the [`file-loader`](https://github.com/webpack-contrib/file-loader) is used by default and all query parameters are passed to it.
You can use other loader using `fallback` option.

The limit can be specified via loader options and defaults to no limit.

**webpack.config.js**
```js
{
loader: 'url-loader',
options: {
limit: 8192
}
}
```

### `mimetype`

Set the MIME type for the file. If unspecified the file extensions will be used to lookup the MIME type.

**webpack.config.js**
```js
{
loader: 'url-loader',
options: {
mimetype: 'image/png'
}
}
```

### `fallback`

**webpack.config.js**
```js
{
loader: 'url-loader',
options: {
fallback: 'responsive-loader'
}
}
```

<h2 align="center">Maintainers</h2>

<table>
<tbody>
<tr>
<td align="center">
<a href="https://github.com/bebraw">
<img width="150" height="150" src="https://github.com/bebraw.png?v=3&s=150">
</br>
Juho Vepsäläinen
</a>
</td>
<td align="center">
<a href="https://github.com/d3viant0ne">
<img width="150" height="150" src="https://github.com/d3viant0ne.png?v=3&s=150">
</br>
Joshua Wiens
</a>
</td>
<td align="center">
<a href="https://github.com/sapegin">
<img width="150" height="150" src="https://github.com/sapegin.png?v=3&s=150">
</br>
Artem Sapegin
</a>
</td>
<td align="center">
<a href="https://github.com/michael-ciniawsky">
<img width="150" height="150" src="https://github.com/michael-ciniawsky.png?v=3&s=150">
</br>
Michael Ciniawsky
</a>
</td>
<td align="center">
<a href="https://github.com/evilebottnawi">
<img width="150" height="150" src="https://github.com/evilebottnawi.png?v=3&s=150">
</br>
Alexander Krasnoyarov
</a>
</td>
</tr>
<tbody>
</table>


[npm]: https://img.shields.io/npm/v/url-loader.svg
[npm-url]: https://npmjs.com/package/url-loader

[tests]: https://circleci.com/gh/webpack-contrib/url-loader/tree/master.svg?style=svg
[tests-url]: https://circleci.com/gh/webpack-contrib/url-loader/tree/master

[cover]: https://codecov.io/gh/webpack-contrib/url-loader/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/url-loader

[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack
30 changes: 30 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
branches:
only:
- master
- next
init:
- git config --global core.autocrlf input
environment:
matrix:
- nodejs_version: '8'
webpack_version: latest
job_part: test
- nodejs_version: '6'
webpack_version: latest
job_part: test
- nodejs_version: '8'
webpack_version: next
job_part: test
build: 'off'
matrix:
fast_finish: true
install:
- ps: Install-Product node $env:nodejs_version x64
- npm i -g npm@latest
- npm install
before_test:
- cmd: npm install webpack@%webpack_version%
test_script:
- node --version
- npm --version
- cmd: npm run ci:%job_part%
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codecov:
branch: master
coverage:
precision: 2
round: down
range: 70...100
status:
project: 'no'
patch: 'yes'
comment: 'off'
31 changes: 31 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable */
const Configuration = {
extends: ['@commitlint/config-angular'],

rules: {
'body-leading-blank': [1, 'always'],
'footer-leading-blank': [1, 'always'],
'header-max-length': [2, 'always', 72],
'scope-case': [2, 'always', 'lower-case'],
'subject-case': [2, 'never', ['start-case', 'pascal-case', 'upper-case']],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'type-enum': [
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test',
],
},
};

module.exports = Configuration;
40 changes: 0 additions & 40 deletions index.js

This file was deleted.

11,310 changes: 11,310 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

87 changes: 71 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,84 @@
{
"name": "url-loader",
"version": "0.6.2",
"version": "1.0.0",
"author": "Tobias Koppers @sokra",
"description": "url loader module for webpack",
"description": "URL Loader for webpack",
"license": "MIT",
"main": "dist/cjs.js",
"files": [
"dist"
],
"scripts": {
"release": "standard-version"
"start": "npm run build -- -w",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
"clean": "del-cli dist",
"commitlint": "commitlint",
"commitmsg": "commitlint -e $GIT_PARAMS",
"lint": "eslint --cache src test",
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"lint-staged": "lint-staged",
"prebuild": "npm run clean",
"prepare": "npm run build",
"release": "standard-version",
"release:ci": "conventional-github-releaser -p angular",
"release:validate": "commitlint --from=$(git describe --tags --abbrev=0) --to=$(git rev-parse HEAD)",
"security": "nsp check",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
"ci:lint": "npm run lint && npm run security",
"ci:test": "npm run test -- --runInBand",
"ci:coverage": "npm run test:coverage -- --runInBand",
"defaults": "webpack-defaults"
},
"dependencies": {
"loader-utils": "^1.0.2",
"mime": "^1.4.1",
"schema-utils": "^0.3.0"
"loader-utils": "^1.1.0",
"mime": "^2.0.3",
"schema-utils": "^0.4.3"
},
"devDependencies": {
"standard-version": "^4.0.0"
"@commitlint/cli": "^5.2.5",
"@commitlint/config-angular": "^5.1.1",
"@webpack-contrib/eslint-config-webpack": "^2.0.2",
"@webpack-contrib/test-utils": "^0.1.2",
"babel-cli": "^6.26.0",
"babel-jest": "^22.0.3",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"conventional-github-releaser": "^2.0.0",
"cross-env": "^5.1.1",
"del": "^3.0.0",
"del-cli": "^1.1.0",
"eslint": "^4.13.1",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-prettier": "^2.4.0",
"file-loader": "^1.1.6",
"husky": "^0.14.3",
"jest": "^22.0.3",
"lint-staged": "^6.0.0",
"memory-fs": "^0.4.1",
"nsp": "^3.1.0",
"pre-commit": "^1.2.2",
"prettier": "^1.9.2",
"standard-version": "^4.2.0",
"webpack": "^4.0.0",
"webpack-defaults": "^2.0.0-rc.2"
},
"peerDependencies": {
"file-loader": "*"
},
"repository": {
"type": "git",
"url": "git+https://github.com/webpack-contrib/url-loader.git"
"engines": {
"node": ">= 6.9.0 || >= 8.9.0"
},
"bugs": {
"url": "https://github.com/webpack-contrib/url-loader/issues"
"peerDependencies": {
"webpack": "^3.0.0 || ^4.0.0"
},
"homepage": "https://github.com/webpack-contrib/url-loader"
"homepage": "https://github.com/webpack-contrib/url-loader",
"repository": "https://github.com/webpack-contrib/url-loader",
"bugs": "https://github.com/webpack-contrib/url-loader/issues",
"pre-commit": "lint-staged",
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
]
}
}
4 changes: 4 additions & 0 deletions src/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const loader = require('./index');

module.exports = loader.default;
module.exports.raw = loader.raw;
45 changes: 45 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-disable
global-require,
no-param-reassign,
prefer-destructuring,
import/no-dynamic-require,
*/
import { getOptions } from 'loader-utils';
import validateOptions from 'schema-utils';
import mime from 'mime';
import schema from './options.json';

// Loader Mode
export const raw = true;

export default function loader(src) {
// Loader Options
const options = getOptions(this) || {};

validateOptions(schema, options, 'URL Loader');

const file = this.resourcePath;
// Set limit for resource inlining (file size)
let limit = options.limit;

if (limit) {
limit = parseInt(limit, 10);
}
// Get MIME type
const mimetype = options.mimetype || mime.getType(file);

// No limit or within the specified limit
if (!limit || src.length < limit) {
if (typeof src === 'string') {
src = Buffer.from(src);
}

return `export default ${JSON.stringify(
`data:${mimetype || ''};base64,${src.toString('base64')}`
)}`;
}

const fallback = require(options.fallback ? options.fallback : 'file-loader');

return fallback.call(this, src);
}
7 changes: 2 additions & 5 deletions options.json → src/options.json
Original file line number Diff line number Diff line change
@@ -2,15 +2,12 @@
"type": "object",
"properties": {
"limit": {
"type": ["number", "string"]
},
"prefix": {
"type": "string"
"type": ["string", "number"]
},
"mimetype": {
"type": "string"
},
"encoding": {
"fallback": {
"type": "string"
}
},
26 changes: 26 additions & 0 deletions test/Errors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable
prefer-destructuring,
*/
import webpack from '@webpack-contrib/test-utils';

describe('Errors', () => {
test('Validation Error', async () => {
const config = {
loader: {
test: /\.png$/,
options: {
limit: {},
},
},
};

const stats = await webpack('fixture.js', config);
const { source } = stats.toJson().modules[0];

// eslint-disable-next-line
const err = () => eval(source);

expect(err).toThrow();
expect(err).toThrowErrorMatchingSnapshot();
});
});
8 changes: 8 additions & 0 deletions test/__snapshots__/Errors.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Errors Validation Error 1`] = `
"Module build failed: ValidationError: URL Loader Invalid Options
options.limit should be string,number
"
`;
3 changes: 3 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Loader Defaults 1`] = `"export default \\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAAAXNSR0IArs4c6QAAGjNJREFUeAHtnQewFMXWx/uSxZxRUTGAAcyYnwpiJhgRFRCM6GeBZaklopaUWoUo9cwIqPhhAjGAWRQTRjAgijnnLOqnAgL3fv3rR+/r29uzO7t3e3Z2t0/V1uzM9Mx0n/nP6dPnnD4tRKDAgcCBwIFK4UCdq6JDhw5dZeHChRfKc4c2NDR0kNtWrnLhWE1woKGuru4X2dKX5fbym2666aU4rc4C1pAhQ/ZetmzZ7RJQG8W5QShTOxyQwKqXuPj3hhtueN7IkSPrc7W8uXny1FNPXa++vv55eXE783j4HziwnAMIoj3+T9Ibb7zxci6uNDNPSkk1VoJqdfNY+B84YHNAYuQyKYQ2s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NCKNrNciPNCukVZvnMxT5+je8OdwkgNswZgigoT1te4tkgo6lsICF33ScOxqgaWZjAAYzSFBECXQiG3V/TCNAHIAB/KOEo6PwCHrsZLR5mnW+LHPRidASaAVSxRN4DEPbhntVBNAEu/LF4i4OKH5AJk/AAPynFcZVrfrylbQAqY+FGvaqOaApb58lCg0WP4ATL0LiQVW/ZLTVriIZWQeJU0wiuGFzULLJNZgExLMo4DLN0F6i3dIe4ZO2Oevo+WOtwLEOktijj71Q4kzQe9DcDSnDC2gIJfFAEw/QNQtQaaKL6YxwOwTG7E/A+YtISKeUnNFUttBGnNvYkqa3AAVpW90LQ0JwArLW+iyuoRgFVlLzQtzQnASsubqLJ6mMDKSg6A8zZXsH+V8SI0x8EB7Hbkj7BJjor/tI+Z+xlzg/RXvS+D/eulfSYDNkDFrORAgQM2ByTgPraPmfsZEMnkEz9JUD1ongz/AwciOLBYLvrwUMQ5dTgDLPaktfl/pIhbkOuCcC5wQLq5rlqwYMFXuTjRCFgTJkz4ToLrMAmuL3NdFM7VJgckLuqlz/QWOa/zf/NxoBGwKCwnhM6S+tY28iZXyt+H8tA/+W4Szlc1Bxpk636VatLTsvs7Ti5acIX0jXIsJ+UNBJJJU9vKmKX2Oe8STgYOLOeABN2fcqb3t1kSy+aQnAoeJJbNlLAfyQE5WlzMybzAevbZZ5dKMfhX5J3CicCB5Rygi5Sx/soemhdYXCOnff8gA9bqAwcDB3JxQALrF7lEoOrh8upY+kboWtKA2k5Kr4xRVZ8L28ABGW69QE4U/lkO+JRiHxtYsK5v377N5chgDRm6u5L8tQzsrG0OSAzUSym1UM7h/FVKqoW1zY3Q+sCBwIHK5cD/A4bJawZvxvyKAAAAAElFTkSuQmCC\\""`;
Binary file added test/fixtures/file.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/file.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions test/fixtures/file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions test/fixtures/fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* eslint-disable */
import png from './file.png';
20 changes: 20 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable
prefer-destructuring,
*/
import webpack from '@webpack-contrib/test-utils';

describe('Loader', () => {
test('Defaults', async () => {
const config = {
loader: {
test: /\.png$/,
options: {},
},
};

const stats = await webpack('fixture.js', config);
const { source } = stats.toJson().modules[0];

expect(source).toMatchSnapshot();
});
});
3 changes: 3 additions & 0 deletions test/options/__snapshots__/fallback.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Options fallback {String} 1`] = `"module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";"`;
5 changes: 5 additions & 0 deletions test/options/__snapshots__/limit.test.js.snap

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions test/options/__snapshots__/mimetype.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Options mimetype {String} 1`] = `"export default \\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAAAXNSR0IArs4c6QAAGjNJREFUeAHtnQewFMXWx/uSxZxRUTGAAcyYnwpiJhgRFRCM6GeBZaklopaUWoUo9cwIqPhhAjGAWRQTRjAgijnnLOqnAgL3fv3rR+/r29uzO7t3e3Z2t0/V1uzM9Mx0n/nP6dPnnD4tRKDAgcCBwIFK4UCdq6JD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HfASM5UrIvReWQ4rmjbtq36AcLtttsu82xA9+mnnyq9jkEC/wFRFDHqRB979dVXlQSTQXJilVVWiSpeUccrEljYlqZPny6efvppp0nAfAOYB7bddlul22yzzTYCYPgi7t2xY0f169Onj5BpChRoGDzkkqYMMvQA47DDDhPdu3cXLmnpq94+7ltxwOLrnjJlimD0lYvWW2890aNHD7Hzzjurri1XWV/nkJB77723+mGaYEDxzDPPqG7U9UxGrXfddZfqJgcNGiQ23nhjV7GKOFYxwEJ5vvPOO8WLL76Yk7FMWUMpZojv+urpPuX0cPHWW28pSXbooYfmvF+pTmI4RYrJCQfiueeeEzNmzIgcsaKrjRo1Shx55JFi//33L1UVEr1PRQAL88G4ceME2yhC+T3qqKME3Z1N2vzw+uuvi59++ilzGqU9acI1BFjo7lDgH3jgAacEQze7++67xQcffCBOOOGEskndYvmTemChe6CgR422MAcgCfbbbz/B5EqTGC0++eSTjcwPzO7eYYcdlERDkS8XofvJCZ+qq542bZqYNWuWU1988803xSWXXCJOO+00sckmm5SrugU/N9XAevjhh5WSHtUqhurHHHNMo9naKMLoMnQ1WsIBPgyTu+yyi9hss82cXWTUM3wfx7QxYMAAseeee6oP6Isvvsh6JEbWMWPGKHC5JHLWBSk4kEpgAY7JkyerUZ+LRxgueRm77757o9MYSLkOPQpaY401lAKPAo0inWZCGo0YMUJgPMVSDw9MQmJff/31AqWejyTtlDpgYQuSWePEa6+95uQduhTdAqM+TXzR99xzT+YaFOXDDz9cdTN296ivSeMWcwW2LLroiRMnij///LNRNeHNrbfeqnSyAw88sNG5tO2kClh8pTfeeKNAr3AREur4448XLVu2zJx+/vnnlZRi1IgkY0QI0ys5bgq728UXXyxuuOEG8fnnn2fayh94xEeEcVXmS2h0Lk07qQLWbbfdFgkqmMjwWxPGx0mTJmWkFL43vvZqce6uvvrq4txzzxVjx45tNPjQ7b/vvvuUlR7dLI2UGmAxMkL62IQtql+/fmrUp8/hKhk/frygC0R3QophCK02QgIPGzZMdYuzZ8/Oah4f1korrd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IHK5cD/A4bJawZvxvyKAAAAAElFTkSuQmCC\\""`;
25 changes: 25 additions & 0 deletions test/options/fallback.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable
prefer-destructuring,
*/
import webpack from '@webpack-contrib/test-utils';

describe('Options', () => {
describe('fallback', () => {
test('{String}', async () => {
const config = {
loader: {
test: /\.png$/,
options: {
limit: 100,
fallback: 'file-loader',
},
},
};

const stats = await webpack('fixture.js', config);
const { source } = stats.toJson().modules[0];

expect(source).toMatchSnapshot();
});
});
});
40 changes: 40 additions & 0 deletions test/options/limit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-disable
prefer-destructuring,
*/
import webpack from '@webpack-contrib/test-utils';

describe('Options', () => {
describe('limit', () => {
test('{Number}', async () => {
const config = {
loader: {
test: /\.png$/,
options: {
limit: 100000,
},
},
};

const stats = await webpack('fixture.js', config);
const { source } = stats.toJson().modules[0];

expect(source).toMatchSnapshot();
});

test('{String}', async () => {
const config = {
loader: {
test: /\.png$/,
options: {
limit: '100000',
},
},
};

const stats = await webpack('fixture.js', config);
const { source } = stats.toJson().modules[0];

expect(source).toMatchSnapshot();
});
});
});
24 changes: 24 additions & 0 deletions test/options/mimetype.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable
prefer-destructuring,
*/
import webpack from '@webpack-contrib/test-utils';

describe('Options', () => {
describe('mimetype', () => {
test('{String}', async () => {
const config = {
loader: {
test: /\.png$/,
options: {
mimetype: 'image/png',
},
},
};

const stats = await webpack('fixture.js', config);
const { source } = stats.toJson().modules[0];

expect(source).toMatchSnapshot();
});
});
});