url-loader
Advanced tools
Comparing version 2.3.0 to 3.0.0
@@ -5,2 +5,12 @@ # Changelog | ||
## [3.0.0](https://github.com/webpack-contrib/url-loader/compare/v2.0.0...v3.0.0) (2019-11-26) | ||
### BREAKING CHANGES | ||
* minimum required nodejs version is `10.13.0` | ||
* rename the `esModules` option to `esModule` | ||
* switch to ES modules by default (the option `esModule` is `true` by default) | ||
## [2.3.0](https://github.com/webpack-contrib/url-loader/compare/v2.2.0...v2.3.0) (2019-11-21) | ||
@@ -7,0 +17,0 @@ |
@@ -21,8 +21,2 @@ "use strict"; | ||
/* eslint-disable | ||
global-require, | ||
no-param-reassign, | ||
prefer-destructuring, | ||
import/no-dynamic-require, | ||
*/ | ||
function shouldTransform(limit, size) { | ||
@@ -53,3 +47,3 @@ if (typeof limit === 'boolean') { | ||
if (shouldTransform(options.limit, src.length)) { | ||
const file = this.resourcePath; // Get MIME type | ||
const file = this.resourcePath; | ||
@@ -59,6 +53,8 @@ const mimetype = options.mimetype || _mime.default.getType(file); | ||
if (typeof src === 'string') { | ||
// eslint-disable-next-line no-param-reassign | ||
src = Buffer.from(src); | ||
} | ||
return `${options.esModules ? 'export default' : 'module.exports ='} ${JSON.stringify(`data:${mimetype || ''};base64,${src.toString('base64')}`)}`; | ||
const esModule = typeof options.esModule !== 'undefined' ? options.esModule : true; | ||
return `${esModule ? 'export default' : 'module.exports ='} ${JSON.stringify(`data:${mimetype || ''};base64,${src.toString('base64')}`)}`; | ||
} // Normalize the fallback. | ||
@@ -71,2 +67,3 @@ | ||
} = (0, _normalizeFallback.default)(options.fallback, options); // Require the fallback. | ||
// eslint-disable-next-line global-require, import/no-dynamic-require | ||
@@ -73,0 +70,0 @@ const fallback = require(fallbackLoader); // Call the fallback, passing a copy of the loader context. The copy has the query replaced. This way, the fallback |
@@ -41,3 +41,3 @@ { | ||
}, | ||
"esModules": { | ||
"esModule": { | ||
"type": "boolean" | ||
@@ -44,0 +44,0 @@ } |
{ | ||
"name": "url-loader", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"description": "A loader for webpack which transforms files into base64 URIs", | ||
@@ -10,23 +10,27 @@ "license": "MIT", | ||
"bugs": "https://github.com/webpack-contrib/url-loader/issues", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/webpack" | ||
}, | ||
"main": "dist/cjs.js", | ||
"engines": { | ||
"node": ">= 8.9.0" | ||
"node": ">= 10.13.0" | ||
}, | ||
"scripts": { | ||
"start": "npm run build -- -w", | ||
"clean": "del-cli dist", | ||
"prebuild": "npm run clean", | ||
"build": "cross-env NODE_ENV=production babel src -d dist --ignore \"src/**/*.test.js\" --copy-files", | ||
"clean": "del-cli dist", | ||
"build": "cross-env NODE_ENV=production babel src -d dist --copy-files", | ||
"commitlint": "commitlint --from=master", | ||
"lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css}\" --list-different", | ||
"lint:js": "eslint --cache src test", | ||
"security": "npm audit", | ||
"lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different", | ||
"lint:js": "eslint --cache .", | ||
"lint": "npm-run-all -l -p \"lint:**\"", | ||
"test:only": "cross-env NODE_ENV=test jest", | ||
"test:watch": "npm run test:only -- --watch", | ||
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage", | ||
"pretest": "npm run lint", | ||
"test": "npm run test:coverage", | ||
"prepare": "npm run build", | ||
"release": "standard-version", | ||
"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" | ||
@@ -38,3 +42,3 @@ }, | ||
"peerDependencies": { | ||
"webpack": "^4.0.0", | ||
"webpack": "^4.0.0 || ^5.0.0", | ||
"file-loader": "*" | ||
@@ -53,8 +57,8 @@ }, | ||
"devDependencies": { | ||
"@babel/cli": "^7.7.0", | ||
"@babel/core": "^7.7.2", | ||
"@babel/preset-env": "^7.7.1", | ||
"@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": "^5.0.2", | ||
"@webpack-contrib/defaults": "^6.2.0", | ||
"@webpack-contrib/eslint-config-webpack": "^3.0.0", | ||
@@ -66,6 +70,6 @@ "babel-jest": "^24.9.0", | ||
"del-cli": "^3.0.0", | ||
"eslint": "^6.6.0", | ||
"eslint": "^6.7.1", | ||
"eslint-config-prettier": "^6.7.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"file-loader": "^4.2.0", | ||
"file-loader": "^5.0.2", | ||
"husky": "^3.1.0", | ||
@@ -75,3 +79,3 @@ "jest": "^24.9.0", | ||
"lint-staged": "^9.4.3", | ||
"memory-fs": "^0.5.0", | ||
"memfs": "^2.16.1", | ||
"npm-run-all": "^4.1.5", | ||
@@ -78,0 +82,0 @@ "prettier": "^1.19.1", |
@@ -211,2 +211,34 @@ <div align="center"> | ||
### `esModule` | ||
Type: `Boolean` | ||
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 syntax using: | ||
**webpack.config.js** | ||
```js | ||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
{ | ||
loader: 'url-loader', | ||
options: { | ||
esModule: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}; | ||
``` | ||
## Contributing | ||
@@ -213,0 +245,0 @@ |
21508
267
133