Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

url-loader

Package Overview
Dependencies
Maintainers
10
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-loader - npm Package Compare versions

Comparing version 1.1.2 to 2.0.0

25

CHANGELOG.md

@@ -1,5 +0,28 @@

# Change Log
# Changelog
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.
## [2.0.0](https://github.com/webpack-contrib/url-loader/compare/v1.1.2...v2.0.0) (2019-06-05)
### Bug Fixes
* rm unnecessary `bin` field ([#163](https://github.com/webpack-contrib/url-loader/issues/163)) ([b603665](https://github.com/webpack-contrib/url-loader/commit/b603665))
* `limit` should always be a number and 0 value handles as number ([#180](https://github.com/webpack-contrib/url-loader/issues/180)) ([d82e453](https://github.com/webpack-contrib/url-loader/commit/d82e453))
* fallback loader will be used than limit is equal or greater ([#179](https://github.com/webpack-contrib/url-loader/issues/179)) ([3c24545](https://github.com/webpack-contrib/url-loader/commit/3c24545))
### Features
* limit option can be boolean ([#181](https://github.com/webpack-contrib/url-loader/issues/181)) ([60d2cb3](https://github.com/webpack-contrib/url-loader/commit/60d2cb3))
### BREAKING CHANGES
* minimum required nodejs version is `8.9.0`
* `limit` should always be a number and 0 value handles as number
* fallback loader will be used than limit is equal or greater (before only when greater)
<a name="1.1.2"></a>

@@ -6,0 +29,0 @@ ## [1.1.2](https://github.com/webpack-contrib/url-loader/compare/v1.1.0...v1.1.2) (2018-10-10)

2

dist/cjs.js

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -3,0 +3,0 @@ const loader = require('./index');

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,50 +6,45 @@ Object.defineProperty(exports, "__esModule", {

});
exports.raw = undefined;
exports.default = loader;
exports.raw = void 0;
var _loaderUtils = require('loader-utils');
var _loaderUtils = require("loader-utils");
var _schemaUtils = require('schema-utils');
var _schemaUtils = _interopRequireDefault(require("schema-utils"));
var _schemaUtils2 = _interopRequireDefault(_schemaUtils);
var _mime = _interopRequireDefault(require("mime"));
var _mime = require('mime');
var _normalizeFallback = _interopRequireDefault(require("./utils/normalizeFallback"));
var _mime2 = _interopRequireDefault(_mime);
var _options = _interopRequireDefault(require("./options.json"));
var _normalizeFallback = require('./utils/normalizeFallback');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _normalizeFallback2 = _interopRequireDefault(_normalizeFallback);
/* eslint-disable
global-require,
no-param-reassign,
prefer-destructuring,
import/no-dynamic-require,
*/
function shouldTransform(limit, size) {
if (typeof limit === 'boolean') {
return limit;
}
var _options = require('./options.json');
if (typeof limit === 'number') {
return size <= parseInt(limit, 10);
}
var _options2 = _interopRequireDefault(_options);
return true;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Loader Mode
const raw = exports.raw = true; /* eslint-disable
global-require,
no-param-reassign,
prefer-destructuring,
import/no-dynamic-require,
*/
function loader(src) {
// Loader Options
const options = (0, _loaderUtils.getOptions)(this) || {};
(0, _schemaUtils.default)(_options.default, options, 'URL Loader'); // No limit or within the specified limit
(0, _schemaUtils2.default)(_options2.default, options, 'URL Loader');
if (shouldTransform(options.limit, src.length)) {
const file = this.resourcePath; // Get MIME type
const file = this.resourcePath;
// Set limit for resource inlining (file size)
let limit = options.limit;
const mimetype = options.mimetype || _mime.default.getType(file);
if (limit) {
limit = parseInt(limit, 10);
}
// Get MIME type
const mimetype = options.mimetype || _mime2.default.getType(file);
// No limit or within the specified limit
if (!limit || src.length < limit) {
if (typeof src === 'string') {

@@ -60,20 +55,22 @@ src = Buffer.from(src);

return `module.exports = ${JSON.stringify(`data:${mimetype || ''};base64,${src.toString('base64')}`)}`;
}
} // Normalize the fallback.
// Normalize the fallback.
const {
loader: fallbackLoader,
options: fallbackOptions
} = (0, _normalizeFallback2.default)(options.fallback, options);
} = (0, _normalizeFallback.default)(options.fallback, options); // Require the fallback.
// Require the fallback.
const fallback = require(fallbackLoader);
const fallback = require(fallbackLoader); // Call the fallback, passing a copy of the loader context. The copy has the query replaced. This way, the fallback
// loader receives the query which was intended for it instead of the query which was intended for url-loader.
// Call the fallback, passing a copy of the loader context. The copy has the query replaced. This way, the fallback
// loader receives the query which was intended for it instead of the query which was intended for url-loader.
const fallbackLoaderContext = Object.assign({}, this, {
query: fallbackOptions
});
return fallback.call(fallbackLoaderContext, src);
} // Loader Mode
return fallback.call(fallbackLoaderContext, src);
}
const raw = true;
exports.raw = raw;

@@ -5,3 +5,3 @@ {

"limit": {
"type": ["string", "number"]
"type": ["boolean", "number"]
},

@@ -8,0 +8,0 @@ "mimetype": {

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -8,6 +8,4 @@ Object.defineProperty(exports, "__esModule", {

var _loaderUtils = require('loader-utils');
var _loaderUtils = _interopRequireDefault(require("loader-utils"));
var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -21,3 +19,2 @@

loader = fallback;
const index = fallback.indexOf('?');

@@ -27,3 +24,3 @@

loader = fallback.substr(0, index);
options = _loaderUtils2.default.parseQuery(fallback.substr(index));
options = _loaderUtils.default.parseQuery(fallback.substr(index));
}

@@ -33,10 +30,14 @@ }

if (fallback !== null && typeof fallback === 'object') {
({ loader, options } = fallback);
({
loader,
options
} = fallback);
}
options = Object.assign({}, originalOptions, options);
delete options.fallback;
return { loader, options };
return {
loader,
options
};
}
{
"name": "url-loader",
"version": "1.1.2",
"version": "2.0.0",
"description": "A loader for webpack which transforms files into base64 URIs",

@@ -10,28 +10,23 @@ "license": "MIT",

"bugs": "https://github.com/webpack-contrib/url-loader/issues",
"bin": "",
"main": "dist/cjs.js",
"engines": {
"node": ">= 6.9.0"
"node": ">= 8.9.0"
},
"scripts": {
"start": "npm run build -- -w",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
"prebuild": "npm run clean",
"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",
"prepublish": "npm run build",
"commitlint": "commitlint --from=master",
"lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css}\" --list-different",
"lint:js": "eslint --cache src test",
"lint": "npm-run-all -l -p \"lint:**\"",
"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",
"security": "npm audit",
"test:only": "cross-env NODE_ENV=test jest",
"test:watch": "cross-env NODE_ENV=test jest --watch",
"test:coverage": "cross-env NODE_ENV=test jest --collectCoverageFrom=\"src/**/*.js\" --coverage",
"pretest": "npm run lint",
"test": "cross-env NODE_ENV=test npm run test:coverage",
"defaults": "webpack-defaults"

@@ -43,3 +38,3 @@ },

"peerDependencies": {
"webpack": "^3.0.0 || ^4.0.0"
"webpack": "^4.0.0"
},

@@ -52,48 +47,31 @@ "dependencies": {

"devDependencies": {
"@commitlint/cli": "^5.2.5",
"@commitlint/config-angular": "^5.1.1",
"@commitlint/config-conventional": "^7.0.1",
"@webpack-contrib/defaults": "^2.4.0",
"@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",
"jest-serializer-path": "^0.1.15",
"lint-staged": "^6.0.0",
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@commitlint/cli": "^8.0.0",
"@commitlint/config-conventional": "^8.0.0",
"@webpack-contrib/defaults": "^5.0.0",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^24.8.0",
"commitlint-azure-pipelines-cli": "^1.0.2",
"cross-env": "^5.2.0",
"del": "^4.1.1",
"del-cli": "^2.0.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.3.0",
"eslint-plugin-import": "^2.17.3",
"file-loader": "^4.0.0",
"husky": "^2.3.0",
"jest": "^24.8.0",
"jest-junit": "^6.4.0",
"lint-staged": "^8.1.7",
"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"
"npm-run-all": "^4.1.5",
"prettier": "^1.17.1",
"standard-version": "^6.0.1",
"webpack": "^4.33.0"
},
"keywords": [
"webpack"
],
"jest": {
"snapshotSerializers": [
"jest-serializer-path"
],
"testEnvironment": "node"
},
"pre-commit": "lint-staged",
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
]
}
]
}

@@ -18,6 +18,2 @@ <div align="center">

## Requirements
This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.
## Getting Started

@@ -35,9 +31,11 @@

**index.js**
```js
import img from './image.png'
import img from './image.png';
```
**webpack.config.js**
```js
// webpack.config.js
module.exports = {

@@ -52,10 +50,10 @@ module: {

options: {
limit: 8192
}
}
]
}
]
}
}
limit: 8192,
},
},
],
},
],
},
};
```

@@ -75,10 +73,22 @@

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

@@ -90,10 +100,23 @@

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

@@ -103,23 +126,62 @@

Type: `Number`
Type: `Number|Boolean`
Default: `undefined`
A `Number` specifying the maximum size of a file in bytes. If the file is
greater than the limit,
[`file-loader`](https://github.com/webpack-contrib/file-loader) is used by
default and all query parameters are passed to it. Using an alternative to
`file-loader` is enabled via the `fallback` option.
The limit can be specified via loader options and defaults to no limit.
#### `Number`
A `Number` specifying the maximum size of a file in bytes. If the file size is
**equal** or **greater** than the limit [`file-loader`](https://github.com/webpack-contrib/file-loader)
will be used (by default) and all query parameters are passed to it.
Using an alternative to `file-loader` is enabled via the `fallback` option.
**webpack.config.js**
```js
// webpack.config.js
{
loader: 'url-loader',
options: {
limit: 8192
}
}
module.exports = {
module: {
rules: [
{
test: /\.(png|jpg|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
},
],
},
};
```
#### `Boolean`
Enable or disable transform files into base64.
**webpack.config.js**
```js
module.exports = {
module: {
rules: [
{
test: /\.(png|jpg|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: false,
},
},
],
},
],
},
};
```
### `mimetype`

@@ -133,10 +195,22 @@

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

@@ -156,19 +230,13 @@

[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]: https://img.shields.io/circleci/project/github/webpack-contrib/url-loader.svg
[tests-url]: https://circleci.com/gh/webpack-contrib/url-loader
[tests]: https://dev.azure.com/webpack-contrib/url-loader/_apis/build/status/webpack-contrib.url-loader?branchName=master
[tests-url]: https://dev.azure.com/webpack-contrib/url-loader/_build/latest?definitionId=2&branchName=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://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
[chat-url]: https://gitter.im/webpack/webpack
[size]: https://packagephobia.now.sh/badge?p=url-loader
[size-url]: https://packagephobia.now.sh/result?p=url-loader
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc