node_modules

This commit is contained in:
saeid
2019-07-15 13:07:31 +04:30
parent d3735c6d30
commit ce1a3ebf9c
35713 changed files with 3639219 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Ben Holloway
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+250
View File
@@ -0,0 +1,250 @@
/*
* MIT License http://opensource.org/licenses/MIT
* Author: Ben Holloway @bholloway
*/
'use strict';
var path = require('path'),
fs = require('fs'),
loaderUtils = require('loader-utils'),
rework = require('rework'),
visit = require('rework-visit'),
convert = require('convert-source-map'),
camelcase = require('camelcase'),
defaults = require('lodash.defaults'),
SourceMapConsumer = require('source-map').SourceMapConsumer;
var findFile = require('./lib/find-file'),
absoluteToRelative = require('./lib/sources-absolute-to-relative'),
adjustSourceMap = require('adjust-sourcemap-loader/lib/process');
var PACKAGE_NAME = require('./package.json').name;
/**
* A webpack loader that resolves absolute url() paths relative to their original source file.
* Requires source-maps to do any meaningful work.
* @param {string} content Css content
* @param {object} sourceMap The source-map
* @returns {string|String}
*/
function resolveUrlLoader(content, sourceMap) {
/* jshint validthis:true */
// details of the file being processed
var loader = this,
filePath = path.dirname(loader.resourcePath);
// webpack 1: prefer loader query, else options object
// webpack 2: prefer loader options
// webpack 3: deprecate loader.options object
// webpack 4: loader.options no longer defined
var options = defaults(
loaderUtils.getOptions(loader),
loader.options && loader.options[camelcase(PACKAGE_NAME)],
{
absolute : false,
sourceMap : loader.sourceMap,
fail : false,
silent : false,
keepQuery : false,
attempts : 0,
debug : false,
root : null,
includeRoot: false
}
);
// validate root directory
var resolvedRoot = (typeof options.root === 'string') && path.resolve(options.root) || undefined,
isValidRoot = resolvedRoot && fs.existsSync(resolvedRoot);
if (options.root && !isValidRoot) {
return handleException('"root" option does not resolve to a valid path');
}
// loader result is cacheable
loader.cacheable();
// incoming source-map
var sourceMapConsumer, contentWithMap, sourceRoot;
if (sourceMap) {
// support non-standard string encoded source-map (per less-loader)
if (typeof sourceMap === 'string') {
try {
sourceMap = JSON.parse(sourceMap);
}
catch (exception) {
return handleException('source-map error', 'cannot parse source-map string (from less-loader?)');
}
}
// Note the current sourceRoot before it is removed
// later when we go back to relative paths, we need to add it again
sourceRoot = sourceMap.sourceRoot;
// leverage adjust-sourcemap-loader's codecs to avoid having to make any assumptions about the sourcemap
// historically this is a regular source of breakage
var absSourceMap;
try {
absSourceMap = adjustSourceMap(this, {format: 'absolute'}, sourceMap);
}
catch (exception) {
return handleException('source-map error', exception.message);
}
// prepare the adjusted sass source-map for later look-ups
sourceMapConsumer = new SourceMapConsumer(absSourceMap);
// embed source-map in css for rework-css to use
contentWithMap = content + convert.fromObject(absSourceMap).toComment({multiline: true});
}
// absent source map
else {
contentWithMap = content;
}
// process
// rework-css will throw on css syntax errors
var reworked;
try {
reworked = rework(contentWithMap, {source: loader.resourcePath})
.use(reworkPlugin)
.toString({
sourcemap : options.sourceMap,
sourcemapAsObject: options.sourceMap
});
}
// fail gracefully
catch (exception) {
return handleException('CSS error', exception);
}
// complete with source-map
if (options.sourceMap) {
// source-map sources seem to be relative to the file being processed
absoluteToRelative(reworked.map.sources, path.resolve(filePath, sourceRoot || '.'));
// Set source root again
reworked.map.sourceRoot = sourceRoot;
// need to use callback when there are multiple arguments
loader.callback(null, reworked.code, reworked.map);
}
// complete without source-map
else {
return reworked;
}
/**
* Push an error for the given exception and return the original content.
* @param {string} label Summary of the error
* @param {string|Error} [exception] Optional extended error details
* @returns {string} The original CSS content
*/
function handleException(label, exception) {
var rest = (typeof exception === 'string') ? [exception] :
(exception instanceof Error) ? [exception.message, exception.stack.split('\n')[1].trim()] :
[];
var message = ' resolve-url-loader cannot operate: ' + [label].concat(rest).filter(Boolean).join('\n ');
if (options.fail) {
loader.emitError(message);
}
else if (!options.silent) {
loader.emitWarning(message);
}
return content;
}
/**
* Plugin for css rework that follows SASS transpilation
* @param {object} stylesheet AST for the CSS output from SASS
*/
function reworkPlugin(stylesheet) {
var URL_STATEMENT_REGEX = /(url\s*\()\s*(?:(['"])((?:(?!\2).)*)(\2)|([^'"](?:(?!\)).)*[^'"]))\s*(\))/g;
// visit each node (selector) in the stylesheet recursively using the official utility method
// each node may have multiple declarations
visit(stylesheet, function visitor(declarations) {
if (declarations) {
declarations
.forEach(eachDeclaration);
}
});
/**
* Process a declaration from the syntax tree.
* @param declaration
*/
function eachDeclaration(declaration) {
var isValid = declaration.value && (declaration.value.indexOf('url') >= 0),
directory;
if (isValid) {
// reverse the original source-map to find the original sass file
var startPosApparent = declaration.position.start,
startPosOriginal = sourceMapConsumer && sourceMapConsumer.originalPositionFor(startPosApparent);
// we require a valid directory for the specified file
directory = startPosOriginal && startPosOriginal.source && path.dirname(startPosOriginal.source);
if (directory) {
// allow multiple url() values in the declaration
// split by url statements and process the content
// additional capture groups are needed to match quotations correctly
// escaped quotations are not considered
declaration.value = declaration.value
.split(URL_STATEMENT_REGEX)
.map(eachSplitOrGroup)
.join('');
}
// source-map present but invalid entry
else if (sourceMapConsumer) {
throw new Error('source-map information is not available at url() declaration');
}
}
/**
* Encode the content portion of <code>url()</code> statements.
* There are 4 capture groups in the split making every 5th unmatched.
* @param {string} token A single split item
* @param i The index of the item in the split
* @returns {string} Every 3 or 5 items is an encoded url everything else is as is
*/
function eachSplitOrGroup(token, i) {
var BACKSLASH_REGEX = /\\/g;
// we can get groups as undefined under certain match circumstances
var initialised = token || '';
// the content of the url() statement is either in group 3 or group 5
var mod = i % 7;
if ((mod === 3) || (mod === 5)) {
// split into uri and query/hash and then find the absolute path to the uri
var split = initialised.split(/([?#])/g),
uri = split[0],
absolute = uri && findFile(options).absolute(directory, uri, resolvedRoot),
query = options.keepQuery ? split.slice(1).join('') : '';
// use the absolute path (or default to initialised)
if (options.absolute) {
return absolute && absolute.replace(BACKSLASH_REGEX, '/').concat(query) || initialised;
}
// module relative path (or default to initialised)
else {
var relative = absolute && path.relative(filePath, absolute),
rootRelative = relative && loaderUtils.urlToRequest(relative, '~');
return (rootRelative) ? rootRelative.replace(BACKSLASH_REGEX, '/').concat(query) : initialised;
}
}
// everything else, including parentheses and quotation (where present) and media statements
else {
return initialised;
}
}
}
}
}
module.exports = resolveUrlLoader;
+168
View File
@@ -0,0 +1,168 @@
'use strict';
var fs = require('fs'),
path = require('path'),
defaults = require('lodash.defaults');
var PACKAGE_NAME = require('../package.json').name;
/**
* Factory for find-file with the given <code>options</code> hash.
* @param {{debug: boolean, attempts:number}} [opt] Optional options hash
*/
function findFile(opt) {
var options = defaults(opt, {
debug: false,
attempts: 0
});
return {
absolute: absolute,
base : base
};
/**
* Search for the relative file reference from the <code>startPath</code> up to the process
* working directory, avoiding any other directories with a <code>package.json</code> or <code>bower.json</code>.
* @param {string} startPath The location of the uri declaration and the place to start the search from
* @param {string} uri The content of the url() statement, expected to be a relative file path
* @param {string} [limit] Optional directory to limit the search to
* @returns {string|null} <code>null</code> where not found else the absolute path to the file
*/
function absolute(startPath, uri, limit) {
var basePath = base(startPath, uri, limit);
return !!basePath && path.resolve(basePath, uri) || null;
}
/**
* Search for the relative file reference from the <code>startPath</code> up to the process
* working directory, avoiding any other directories with a <code>package.json</code> or <code>bower.json</code>.
* @param {string} startPath The location of the uri declaration and the place to start the search from
* @param {string} uri The content of the url() statement, expected to be a relative file path
* @param {string} [limit] Optional directory to limit the search to
* @returns {string|null} <code>null</code> where not found else the base path upon which the uri may be resolved
*/
function base(startPath, uri, limit) {
var messages = [];
// ensure we have some limit to the search
limit = limit && path.resolve(limit) || process.cwd();
// #69 limit searching: make at least one attempt
var remaining = Math.max(0, options.attempts) || 1E+9;
// ignore explicit uris data|http|https and ensure we are at a valid start path
var absoluteStart = !(/^(data|https?):/.test(uri)) && path.resolve(startPath);
if (absoluteStart) {
// find path to the root, stopping at cwd, package.json or bower.json
var pathToRoot = [];
var isWorking;
do {
pathToRoot.push(absoluteStart);
isWorking = testWithinLimit(absoluteStart) && testNotPackage(absoluteStart);
absoluteStart = path.resolve(absoluteStart, '..');
} while (isWorking);
// start a queue with the path to the root
var appendLimit = options.includeRoot && pathToRoot.indexOf(limit) === -1 ? limit : [];
var queue = pathToRoot.concat(appendLimit);
// the queue pattern ensures that we favour paths closest the the start path
// process the queue until empty or until we exhaust our attempts
while (queue.length && (remaining-- > 0)) {
// shift the first item off the queue, consider it the base for our relative uri
var basePath = queue.shift();
var fullPath = path.resolve(basePath, uri);
messages.push(basePath);
// file exists so convert to a dataURI and end
if (fs.existsSync(fullPath)) {
flushMessages('FOUND');
return basePath;
}
// enqueue subdirectories that are not packages and are not in the root path
else {
enqueue(queue, basePath);
}
}
// interrupted by options.attempts
if (queue.length) {
flushMessages('NOT FOUND (INTERRUPTED)');
}
// not found
else {
flushMessages('NOT FOUND');
return null;
}
}
// ignored
else {
flushMessages('IGNORED');
return null;
}
/**
* Enqueue subdirectories that are not packages and are not in the root path
* @param {Array} queue The queue to add to
* @param {string} basePath The path to consider
*/
function enqueue(queue, basePath) {
fs.readdirSync(basePath)
.filter(function notHidden(filename) {
return (filename.charAt(0) !== '.');
})
.map(function toAbsolute(filename) {
return path.join(basePath, filename);
})
.filter(function directoriesOnly(absolutePath) {
return fs.existsSync(absolutePath) && fs.statSync(absolutePath).isDirectory();
})
.filter(function notInRootPath(absolutePath) {
return (pathToRoot.indexOf(absolutePath) < 0);
})
.filter(testNotPackage)
.forEach(function enqueue(absolutePath) {
queue.push(absolutePath);
});
}
/**
* Test whether the given directory is above but not equal to any of the project root directories.
* @param {string} absolutePath An absolute path
* @returns {boolean} True where a package.json or bower.json exists, else False
*/
function testWithinLimit(absolutePath) {
var relative = path.relative(limit, absolutePath);
return !!relative && (relative.slice(0, 2) !== '..');
}
/**
* Print verbose debug info where <code>options.debug</code> is in effect.
* @param {string} result Final text to append to the message
*/
function flushMessages(result) {
if (options.debug) {
var text = ['\n' + PACKAGE_NAME + ': ' + uri]
.concat(messages)
.concat(result)
.join('\n ');
console.log(text);
}
}
}
/**
* Test whether the given directory is the root of its own package.
* @param {string} absolutePath An absolute path
* @returns {boolean} True where a package.json or bower.json exists, else False
*/
function testNotPackage(absolutePath) {
return ['package.json', 'bower.json'].every(function fileFound(file) {
return !fs.existsSync(path.resolve(absolutePath, file));
});
}
}
module.exports = findFile;
+20
View File
@@ -0,0 +1,20 @@
/*
* MIT License http://opensource.org/licenses/MIT
* Author: Ben Holloway @bholloway
*/
'use strict';
var path = require('path');
/**
* Convert the given array of absolute URIs to relative URIs (in place).
* @param {Array} sources The source map sources array
* @param {string} basePath The base path to make relative to
*/
module.exports = function sourcesAbsoluteToRelative(sources, basePath) {
sources.forEach(sourceToRelative);
function sourceToRelative(value, i, array) {
array[i] = path.relative(basePath, value);
}
};
+64
View File
@@ -0,0 +1,64 @@
'use strict';
function preserveCamelCase(str) {
let isLastCharLower = false;
let isLastCharUpper = false;
let isLastLastCharUpper = false;
for (let i = 0; i < str.length; i++) {
const c = str[i];
if (isLastCharLower && /[a-zA-Z]/.test(c) && c.toUpperCase() === c) {
str = str.substr(0, i) + '-' + str.substr(i);
isLastCharLower = false;
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = true;
i++;
} else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(c) && c.toLowerCase() === c) {
str = str.substr(0, i - 1) + '-' + str.substr(i - 1);
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = false;
isLastCharLower = true;
} else {
isLastCharLower = c.toLowerCase() === c;
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = c.toUpperCase() === c;
}
}
return str;
}
module.exports = function (str) {
if (arguments.length > 1) {
str = Array.from(arguments)
.map(x => x.trim())
.filter(x => x.length)
.join('-');
} else {
str = str.trim();
}
if (str.length === 0) {
return '';
}
if (str.length === 1) {
return str.toLowerCase();
}
if (/^[a-z0-9]+$/.test(str)) {
return str;
}
const hasUpperCase = str !== str.toLowerCase();
if (hasUpperCase) {
str = preserveCamelCase(str);
}
return str
.replace(/^[_.\- ]+/, '')
.toLowerCase()
.replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase());
};
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+74
View File
@@ -0,0 +1,74 @@
{
"_from": "camelcase@^4.1.0",
"_id": "camelcase@4.1.0",
"_inBundle": false,
"_integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=",
"_location": "/resolve-url-loader/camelcase",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "camelcase@^4.1.0",
"name": "camelcase",
"escapedName": "camelcase",
"rawSpec": "^4.1.0",
"saveSpec": null,
"fetchSpec": "^4.1.0"
},
"_requiredBy": [
"/resolve-url-loader"
],
"_resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz",
"_shasum": "d545635be1e33c542649c69173e5de6acfae34dd",
"_spec": "camelcase@^4.1.0",
"_where": "D:\\Atom\\Git\\Laravel_CSSd\\node_modules\\resolve-url-loader",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bugs": {
"url": "https://github.com/sindresorhus/camelcase/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Convert a dash/dot/underscore/space separated string to camelCase: foo-bar → fooBar",
"devDependencies": {
"ava": "*",
"xo": "*"
},
"engines": {
"node": ">=4"
},
"files": [
"index.js"
],
"homepage": "https://github.com/sindresorhus/camelcase#readme",
"keywords": [
"camelcase",
"camel-case",
"camel",
"case",
"dash",
"hyphen",
"dot",
"underscore",
"separator",
"string",
"text",
"convert"
],
"license": "MIT",
"name": "camelcase",
"repository": {
"type": "git",
"url": "git+https://github.com/sindresorhus/camelcase.git"
},
"scripts": {
"test": "xo && ava"
},
"version": "4.1.0",
"xo": {
"esnext": true
}
}
+57
View File
@@ -0,0 +1,57 @@
# camelcase [![Build Status](https://travis-ci.org/sindresorhus/camelcase.svg?branch=master)](https://travis-ci.org/sindresorhus/camelcase)
> Convert a dash/dot/underscore/space separated string to camelCase: `foo-bar` → `fooBar`
## Install
```
$ npm install --save camelcase
```
## Usage
```js
const camelCase = require('camelcase');
camelCase('foo-bar');
//=> 'fooBar'
camelCase('foo_bar');
//=> 'fooBar'
camelCase('Foo-Bar');
//=> 'fooBar'
camelCase('--foo.bar');
//=> 'fooBar'
camelCase('__foo__bar__');
//=> 'fooBar'
camelCase('foo bar');
//=> 'fooBar'
console.log(process.argv[3]);
//=> '--foo-bar'
camelCase(process.argv[3]);
//=> 'fooBar'
camelCase('foo', 'bar');
//=> 'fooBar'
camelCase('__foo__', '--bar');
//=> 'fooBar'
```
## Related
- [decamelize](https://github.com/sindresorhus/decamelize) - The inverse of this module
- [uppercamelcase](https://github.com/SamVerschueren/uppercamelcase) - Like this module, but to PascalCase instead of camelCase
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)
+76
View File
@@ -0,0 +1,76 @@
{
"_from": "resolve-url-loader@^2.3.1",
"_id": "resolve-url-loader@2.3.2",
"_inBundle": false,
"_integrity": "sha512-sc/UVgiADdoTc+4cGPB7cUCnlEkzlxD1NXHw4oa9qA0fp30H8mAQ2ePJBP9MQ029DUuhEPouhNdvzT37pBCV0g==",
"_location": "/resolve-url-loader",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "resolve-url-loader@^2.3.1",
"name": "resolve-url-loader",
"escapedName": "resolve-url-loader",
"rawSpec": "^2.3.1",
"saveSpec": null,
"fetchSpec": "^2.3.1"
},
"_requiredBy": [
"#DEV:/"
],
"_resolved": "https://registry.npmjs.org/resolve-url-loader/-/resolve-url-loader-2.3.2.tgz",
"_shasum": "83bb9ebc392b66c563795eef22f078970357a26e",
"_spec": "resolve-url-loader@^2.3.1",
"_where": "D:\\Atom\\Git\\Laravel_CSSd",
"author": {
"name": "bholloway"
},
"bugs": {
"url": "https://github.com/bholloway/resolve-url-loader/issues"
},
"bundleDependencies": false,
"dependencies": {
"adjust-sourcemap-loader": "^1.1.0",
"camelcase": "^4.1.0",
"convert-source-map": "^1.5.1",
"loader-utils": "^1.1.0",
"lodash.defaults": "^4.0.0",
"rework": "^1.0.1",
"rework-visit": "^1.0.0",
"source-map": "^0.5.7",
"urix": "^0.1.0"
},
"deprecated": false,
"description": "Webpack loader that resolves relative paths in url() statements based on the original source file",
"devDependencies": {
"jshint": "^2.9.5"
},
"files": [
"index.js",
"lib"
],
"homepage": "https://github.com/bholloway/resolve-url-loader",
"keywords": [
"webpack",
"loader",
"css",
"normalize",
"rewrite",
"resolve",
"url",
"sass",
"relative",
"file"
],
"license": "MIT",
"main": "index.js",
"name": "resolve-url-loader",
"repository": {
"type": "git",
"url": "git+https://github.com/bholloway/resolve-url-loader.git"
},
"scripts": {
"lint": "jshint index.js lib"
},
"version": "2.3.2"
}
+216
View File
@@ -0,0 +1,216 @@
# Resolve URL Loader
[![NPM](https://nodei.co/npm/resolve-url-loader.png)](http://github.com/bholloway/resolve-url-loader)
Webpack loader that resolves relative paths in url() statements based on the original source file.
Use in conjunction with the [sass-loader](https://www.npmjs.com/package/sass-loader) and specify your asset `url()` relative to the `.scss` file in question.
This loader will use the source-map from the SASS compiler to locate the original `.scss` source file and write a more Webpack-friendly path for your asset. The CSS loader can then locate your asset for individual processing.
## Getting started
```bash
# via yarn
yarn add resolve-url-loader --dev
# via npm
npm install resolve-url-loader --save-dev
```
## Usage
Plain CSS works fine:
``` javascript
var css = require('!css-loader!resolve-url-loader!./file.css');
```
or using [sass-loader](https://github.com/jtangelder/sass-loader):
``` javascript
var css = require('!css-loader!resolve-url-loader!sass-loader?sourceMap!./file.scss');
```
Use in tandem with the [`style-loader`](https://github.com/webpack/style-loader) to compile sass and to add the css rules to your document:
``` javascript
require('!style!css!resolve-url!./file.css');
```
and
``` javascript
require('!style-loader!css-loader!resolve-url-loader!sass-loader?sourceMap!./file.scss');
```
### Apply via webpack config
It is preferable to adjust your `webpack.config` so to avoid having to prefix every `require()` statement:
``` javascript
module.exports = {
module: {
loaders: [
{
test : /\.css$/,
loaders: ['style-loader', 'css-loader', 'resolve-url-loader']
}, {
test : /\.scss$/,
loaders: ['style-loader', 'css-loader', 'resolve-url-loader', 'sass-loader?sourceMap']
}
]
}
};
```
### IMPORTANT
#### Source maps required
Note that **source maps** must be enabled on any preceding loader. In the above example we use `sass?sourceMap`.
In some use cases (no preceding transpiler) there will be no incoming source map. Therefore we do not warn if the source-map is missing.
However if there is an incoming source-map then it must imply `source` information at each CSS `url()` statement.
#### Don't omit `-loader`
> Your `Webpack.config.js` should **always** use the long-form of the loader name (i.e. the `-loader` suffix).
There is another package called `resolve-url` which Webpack can confuse with `resolve-url-loader`.
There are other common examples. Such as `jshint` and `jshint-loader` packages being confused.
These conflicts are **very hard to debug** and will send you crazy. Your `Webpack.config.js` should **always** use the long-form of the loader name (i.e. the `-loader` suffix)
### Options
Options may be set using [query parameters](https://webpack.github.io/docs/using-loaders.html#query-parameters) or by using [programmatic parameters](https://webpack.github.io/docs/how-to-write-a-loader.html#programmable-objects-as-query-option). Programmatic means the following in your `webpack.config`.
``` javascript
module.exports = {
resolveUrlLoader: {
...
}
}
```
Where `...` is a hash of any of the following options.
* `sourceMap` Generate a source-map.
* `attempts` Limit searching for any files not where they are expected to be. This is unlimited by default so you will want to set it `1` or some small value.
* `silent` Do not display warnings on CSS syntax or source-map error.
* `fail` Syntax or source-map errors will result in an error.
* `keepQuery` Keep query string and hash within url. I.e. `url('./MyFont.eot?#iefix')`, `url('./MyFont.svg#oldiosfix')`.
* `debug` Show verbose information on the file paths being searched.
* `root` An optional directory within which search may be performed. Relative paths are permitted. Where omitted `process.cwd()` is used and should be sufficient for most use cases.
There are some additional hacks available without support. Only do this if you know what you are doing.
* `absolute` Forces the url() to be resolved to an absolute path. This is considered
[bad practice](http://webpack.github.io/docs/how-to-write-a-loader.html#should-not-embed-absolute-paths).
* `includeRoot` (experimental, non-performant) Include the project `root` in file search. The `root` option need not be specified but `includeRoot` is only really useful if your `root` directory is shallower than your build working directory.
Note that query parameters take precedence over programmatic parameters.
## How it works
A [rework](https://github.com/reworkcss/rework) process is run on incoming CSS.
Each `url()` statement that implies an asset triggers a file search using node `fs` operations. The asset should be relative to the original source file that was transpiled. This original source is determined by consulting the incoming source-map at the point of the `url()` statement.
Usually the asset is found relative to the original source file `O(1)`.
However in cases where there is no immediate match, we start searching both deeper and shallower from the starting directory `O(n)`. Note that `n` may be limited by the `attempts` option.
This file search "magic" is mainly for historic reasons, to work around broken packages whose assets are not where we would expect.
Shallower paths must be limited to avoid the whole file system from being considered. Progressively shallower paths within the `root` will be considered. Paths featuring a `package.json` or `bower.json` file will not be considered.
If the asset is not found then the `url()` statement will not be updated with a Webpack module-relative path. However if the `url()` statement has no source-map `source` information the loader will fail.
The loader will also fail when input source-map `sources` cannot all be resolved relative to some consistent path within `root`.
Use the `debug` option to see exactly what paths are being searched.
## Limitations / Known-issues
### File search "magic"
Failure to find an asset will trigger a file search of your project.
This feature was for historic reasons, to work around broken packages, whose assets are not where we would expect. Such problems are rare now and many users may not be aware of the search feature.
We now have the `attempts` option to limit this feature. However by default it is unlimited (`attempts=0`) which could make your build non-performant.
You should explicitly set `attempts=1` and increase the value only if needed. We will look to make this the default in the next major release.
### Mixins
Where `url()` statements are created in a mixin the source file may then be the mixin file, and not the file calling the mixin. Obviously this is **not** the desired behaviour.
The incoming source map can vary greatly with different transpilers and their mixins. Use a [source map visualiser](http://sokra.github.io/source-map-visualization/#custom-choose) to see more. If the source-map shows the correct original file and the mixin still doesn't work then raise an issue and point to the visualisation.
Ultimately you will need to work around this. Try to avoid the mixin. Worst case you can try the `includeRoot` option to force a search of your project sources.
### Compatiblity
#### Webpack
This loader was written for Webpack 1 and has been tweaked to also support with Webpack 2.
If you find any Webpack 2 problems please comment on any similar existing issue or raise a new one.
#### Node-sass
> **IMPORTANT**
>
> Avoid the combination of **Webpack 1** with **node-sass@^4.0.0**.
>
> Use **Webpack 2** if you need latest **node-sass**
Since `node-sass@>=4.0.0` source-maps have sometimes featured negative column values. Since this loader relies on source-maps this can cause a fatal error.
I don't have a lot of data on this. If you are stuck in Webpack 1 and find that this combination actually works ok for you please let me know.
## Getting help
Webpack is difficult to configure but extremely rewarding.
I am happy for you to **raise an issue** to ask a question regarding this package. However ensure you follow the check-list first.
Currently I am **not** [dogfooding](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) this loader in my own work. I may rely on you being able to isolate the problem in a simple example project and to help debug.
I am happy this loader helps so many people. Open-source is provided as-is so please try not project your frustrations. There are some really great people who follow this project who can help.
### Issues
Before raising a new issue:
* remove this loader and make sure it is not a problem with a different loader in your config (most often the case)
* check [stack overflow](http://stackoverflow.com/search?q=resolve-url-loader) for an answer
* review [previous issues](/issues?utf8=%E2%9C%93&q=is%3Aissue) that may be similar
* be prepared to create a **simple open-source project** that exhibits your problem, should the solution not be immediately obvious to us
* be prepared to use a [source map visualisation](http://sokra.github.io/source-map-visualization/#custom-choose) to check the transpiler has correct source maps coming out
* (ideally) debug some code and let me know where the problem sits
### Pull requests
I am happy to take **pull requests**, however:
* Ensure your change is **backwards compatible** - not all users will be using the same version of Webpack or SASS that you do.
* Follow the **existing code style**.
* Uncomon use-cases/fixes should be opt-in per a new **option**.
* Do **not** overwrite existing variables with new values. I would prefer your change variable names elsewhere if necessary.
* Add **comments** that describe why the code is necessary - i.e. what edge case are we solving. Otherwise we may rewrite later and break your use-case.