pax_global_header00006660000000000000000000000064131152053230014505gustar00rootroot0000000000000052 comment=743aef27df5a594d8c02df407ae03d15b7a92a64 file-loader-0.11.2/000077500000000000000000000000001311520532300137515ustar00rootroot00000000000000file-loader-0.11.2/.github/000077500000000000000000000000001311520532300153115ustar00rootroot00000000000000file-loader-0.11.2/.github/ISSUE_TEMPLATE.md000066400000000000000000000013341311520532300200170ustar00rootroot00000000000000 **Do you want to request a *feature* or report a *bug*?** **What is the current behavior?** **If the current behavior is a bug, please provide the steps to reproduce.** **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.** file-loader-0.11.2/.github/PULL_REQUEST_TEMPLATE.md000066400000000000000000000013141311520532300211110ustar00rootroot00000000000000 **What kind of change does this PR introduce?** **Did you add tests for your changes?** **If relevant, did you update the README?** **Summary** **Does this PR introduce a breaking change?** **Other information** file-loader-0.11.2/.github/assets/000077500000000000000000000000001311520532300166135ustar00rootroot00000000000000file-loader-0.11.2/.github/assets/file_loader_icon.svg000066400000000000000000000042121311520532300226100ustar00rootroot00000000000000 file_loader_icon Created with Sketch. file:// file-loader-0.11.2/.gitignore000066400000000000000000000001161311520532300157370ustar00rootroot00000000000000# development /node_modules /coverage *.log # dotfiles .* !.gitignore *~ *#* file-loader-0.11.2/.travis.yml000066400000000000000000000012631311520532300160640ustar00rootroot00000000000000sudo: false language: node_js branches: only: - master matrix: fast_finish: true include: # - os: linux # node_js: "7" # env: WEBPACK_VERSION="2.2.0" JOB_PART=lint - os: linux node_js: "6" env: WEBPACK_VERSION="2.2.0" JOB_PART=test - os: linux node_js: "4.3" env: WEBPACK_VERSION="2.2.0" JOB_PART=test - os: linux node_js: "7" env: WEBPACK_VERSION="2.2.0" JOB_PART=test before_install: - nvm --version - node --version before_script: - 'if [ "$WEBPACK_VERSION" ]; then npm install webpack@^$WEBPACK_VERSION; fi' script: - npm run travis:$JOB_PART # after_success: # - bash <(curl -s https://codecov.io/bash)file-loader-0.11.2/CHANGELOG.md000066400000000000000000000037431311520532300155710ustar00rootroot00000000000000# Change Log 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. ## [0.11.2](https://github.com/webpack/file-loader/compare/v0.11.1...v0.11.2) (2017-06-05) ### Bug Fixes * **index:** allow to override publicPath with an empty string ([#145](https://github.com/webpack/file-loader/issues/145)) ([26ab81a](https://github.com/webpack/file-loader/commit/26ab81a)) * init `publicPath` to undefined ([#159](https://github.com/webpack/file-loader/issues/159)) ([e4c0b2a](https://github.com/webpack/file-loader/commit/e4c0b2a)) ## [0.11.1](https://github.com/webpack/file-loader/compare/v0.11.0...v0.11.1) (2017-04-01) ### Bug Fixes * outputPath function overriden by useRelativePath ([#139](https://github.com/webpack/file-loader/issues/139)) ([80cdee2](https://github.com/webpack/file-loader/commit/80cdee2)) # [0.11.0](https://github.com/webpack/file-loader/compare/v0.10.1...v0.11.0) (2017-03-31) ### Features * Emit files with relative urls ([#135](https://github.com/webpack/file-loader/issues/135)) ([dbcd6cc](https://github.com/webpack/file-loader/commit/dbcd6cc)) ## [0.10.1](https://github.com/webpack/file-loader/compare/v0.10.0...v0.10.1) (2017-02-25) ### Bug Fixes * **getOptions:** deprecation warn in loaderUtils ([#129](https://github.com/webpack/file-loader/issues/129)) ([a8358a0](https://github.com/webpack/file-loader/commit/a8358a0)) # [0.10.0](https://github.com/webpack/file-loader/compare/v0.9.0...v0.10.0) (2017-01-28) ### Features * **resources:** specify custom public file name ([6833c70](https://github.com/webpack/file-loader/commit/6833c70)) # Change Log 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. file-loader-0.11.2/LICENSE000066400000000000000000000020571311520532300147620ustar00rootroot00000000000000Copyright JS Foundation and other contributors 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. file-loader-0.11.2/README.md000066400000000000000000000122211311520532300152260ustar00rootroot00000000000000[![npm][npm]][npm-url] [![node][node]][node-url] [![deps][deps]][deps-url] [![tests][tests]][tests-url] [![coverage][cover]][cover-url] [![chat][chat]][chat-url]

File Loader

Instructs webpack to emit the required object as file and to return its public url.

Install

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

Usage

By default the filename of the resulting file is the MD5 hash of the file's contents with the original extension of the required resource. ``` javascript var url = require("file-loader!./file.png"); // => emits file.png as file in the output directory and returns the public url // => returns i. e. "/public-path/0dcbbaa701328a3c262cfd45869e351f.png" ``` By default a file is emitted, however this can be disabled if required (e.g. for server side packages). ``` javascript var url = require("file-loader?emitFile=false!./file.png"); // => returns the public url but does NOT emit a file // => returns i. e. "/public-path/0dcbbaa701328a3c262cfd45869e351f.png" ``` #### Filename templates You can configure a custom filename template for your file using the query parameter `name`. For instance, to copy a file from your `context` directory into the output directory retaining the full directory structure, you might use `?name=[path][name].[ext]`. By default, the path and name you specify will output the file in that same directory and will also use that same URL path to access the file. You can specify custom output and public paths by using the `outputPath`, `publicPath` and `useRelativePath` query name parameters: ``` use: "file-loader?name=[name].[ext]&publicPath=assets/foo/&outputPath=app/images/" ``` `useRelativePath` should be `true` if you wish to generate relative URL to the each file context ```javascript { loader: 'file-loader', query: { useRelativePath: process.env.NODE_ENV === "production" } } ``` #### Filename template placeholders * `[ext]` the extension of the resource * `[name]` the basename of the resource * `[path]` the path of the resource relative to the `context` query parameter or option. * `[hash]` the hash of the content, `hex`-encoded `md5` by default * `[:hash::]` optionally you can configure * other `hashType`s, i. e. `sha1`, `md5`, `sha256`, `sha512` * other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64` * and `length` the length in chars * `[N]` the N-th match obtained from matching the current file name against the query param `regExp` #### Examples ``` javascript require("file-loader?name=js/[hash].script.[ext]!./javascript.js"); // => js/0dcbbaa701328a3c262cfd45869e351f.script.js require("file-loader?name=html-[hash:6].html!./page.html"); // => html-109fa8.html require("file-loader?name=[hash]!./flash.txt"); // => c31e9820c001c9c4a86bce33ce43b679 require("file-loader?name=[sha512:hash:base64:7].[ext]!./image.png"); // => gdyb21L.png // use sha512 hash instead of md5 and with only 7 chars of base64 require("file-loader?name=img-[sha512:hash:base64:7].[ext]!./image.jpg"); // => img-VqzT5ZC.jpg // use custom name, sha512 hash instead of md5 and with only 7 chars of base64 require("file-loader?name=picture.png!./myself.png"); // => picture.png require("file-loader?name=[path][name].[ext]?[hash]!./dir/file.png") // => dir/file.png?e43b20c069c4a01867c31e98cbce33c9 ```

Contributing

Don't hesitate to create a pull request. Every contribution is appreciated. In development you can start the tests by calling `npm test`.

Maintainers


Tobias Koppers

Kees Kluskens

Mo Bitar

LICENSE

MIT [npm]: https://img.shields.io/npm/v/file-loader.svg [npm-url]: https://npmjs.com/package/file-loader [node]: https://img.shields.io/node/v/file-loader.svg [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]: http://img.shields.io/travis/webpack-contrib/file-loader.svg [tests-url]: https://travis-ci.org/webpack-contrib/file-loader [cover]: https://coveralls.io/repos/github/webpack-contrib/file-loader/badge.svg [cover-url]: https://coveralls.io/github/webpack-contrib/file-loader [chat]: https://badges.gitter.im/webpack/webpack.svg [chat-url]: https://gitter.im/webpack/webpack file-loader-0.11.2/appveyor.yml000066400000000000000000000007561311520532300163510ustar00rootroot00000000000000# appveyor file # http://www.appveyor.com/docs/appveyor-yml init: - git config --global core.autocrlf input # what combinations to test environment: matrix: - nodejs_version: 0.10 - nodejs_version: 0.11 # combinations having this can fail matrix: allow_failures: - nodejs_version: 0.11 install: - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) - npm install build: off test_script: - node --version - npm --version - cmd: npm test file-loader-0.11.2/index.js000066400000000000000000000044151311520532300154220ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var path = require("path"); var loaderUtils = require("loader-utils"); module.exports = function(content) { this.cacheable && this.cacheable(); if(!this.emitFile) throw new Error("emitFile is required from module system"); var query = loaderUtils.getOptions(this) || {}; var configKey = query.config || "fileLoader"; var options = this.options[configKey] || {}; var config = { publicPath: undefined, useRelativePath: false, name: "[hash].[ext]" }; // options takes precedence over config Object.keys(options).forEach(function(attr) { config[attr] = options[attr]; }); // query takes precedence over config and options Object.keys(query).forEach(function(attr) { config[attr] = query[attr]; }); var context = config.context || this.options.context; var url = loaderUtils.interpolateName(this, config.name, { context: context, content: content, regExp: config.regExp }); var outputPath = ""; var filePath = this.resourcePath; if (config.useRelativePath) { var issuerContext = this._module && this._module.issuer && this._module.issuer.context || context; var relativeUrl = issuerContext && path.relative(issuerContext, filePath).split(path.sep).join("/"); var relativePath = relativeUrl && path.dirname(relativeUrl) + "/"; if (~relativePath.indexOf("../")) { outputPath = path.posix.join(outputPath, relativePath, url); } else { outputPath = relativePath + url; } url = relativePath + url; } else if (config.outputPath) { // support functions as outputPath to generate them dynamically outputPath = ( typeof config.outputPath === "function" ? config.outputPath(url) : config.outputPath + url ); url = outputPath; } else { outputPath = url; } var publicPath = "__webpack_public_path__ + " + JSON.stringify(url); if (config.publicPath !== undefined) { // support functions as publicPath to generate them dynamically publicPath = JSON.stringify( typeof config.publicPath === "function" ? config.publicPath(url) : config.publicPath + url ); } if (query.emitFile === undefined || query.emitFile) { this.emitFile(outputPath, content); } return "module.exports = " + publicPath + ";"; }; module.exports.raw = true; file-loader-0.11.2/package.json000066400000000000000000000014001311520532300162320ustar00rootroot00000000000000{ "name": "file-loader", "version": "0.11.2", "author": "Tobias Koppers @sokra", "description": "file loader module for webpack", "files": [ "index.js" ], "dependencies": { "loader-utils": "^1.0.2" }, "devDependencies": { "should": "~4.0.4", "standard-version": "^4.0.0", "mocha": "~1.21.3" }, "scripts": { "test": "mocha -R spec", "travis:test": "npm run test", "release": "standard-version" }, "repository": { "type": "git", "url": "https://github.com/webpack/file-loader.git" }, "bugs": { "url": "https://github.com/webpack/file-loader/issues" }, "homepage": "https://github.com/webpack/file-loader", "main": "index.js", "directories": { "test": "test" }, "license": "MIT" } file-loader-0.11.2/test/000077500000000000000000000000001311520532300147305ustar00rootroot00000000000000file-loader-0.11.2/test/correct-filename.test.js000066400000000000000000000123321311520532300214640ustar00rootroot00000000000000var should = require("should"); var path = require("path"); var fileLoader = require("../"); function run(resourcePath, query, content) { content = content || new Buffer("1234"); var file = null; var context = { resourcePath: resourcePath, query: "?" + query, options: { context: "/this/is/the/context" }, emitFile: function(url, content2) { content2.should.be.eql(content); file = url; } }; var result = fileLoader.call(context, content) return { file: file, result: result } } function run_with_options(resourcePath,options, content) { content = content || new Buffer("1234"); var file = null; var context = { resourcePath: resourcePath, options: { "fileLoader": options, context: "/this/is/the/context" }, emitFile: function(url, content2) { content2.should.be.eql(content); file = url; } }; var result = fileLoader.call(context, content) return { file: file, result: result } } function test(excepted, resourcePath, query, content) { run(resourcePath, query, content).file.should.be.eql(excepted); } describe("correct-filename", function() { it("should process defaults correctly", function() { test("81dc9bdb52d04dc20036dbd8313ed055.txt", "/file.txt", ""); test("81dc9bdb52d04dc20036dbd8313ed055.png", "/file.png", ""); test("81dc9bdb52d04dc20036dbd8313ed055.txt", "file.txt", ""); test("81dc9bdb52d04dc20036dbd8313ed055.bin", "", ""); }); it("should process name correctly", function() { test("file.txt", "/file.txt", "name=[name].[ext]"); test("file.png", "/file.png", "name=[name].[ext]"); test("file.txt", "file.txt", "name=[name].[ext]"); test("file.bin", "", "name=[name].[ext]"); test("file", "/file.txt", "name=[name]"); test("81dc9bdb52d04dc20036dbd8313ed055", "/file.txt", "name=[hash]"); test("81dc9bdb52d04dc20036dbd8313ed055/file.txt", "/file.txt", "name=[hash]/[name].[ext]"); test("file.txt", "/this/is/the/context/file.txt", "name=[path][name].[ext]"); test("dir/file.txt", "/this/is/the/context/dir/file.txt", "name=[path][name].[ext]"); test("dir/sub/file.txt", "/this/is/the/context/dir/sub/file.txt", "name=[path][name].[ext]"); test("_/_/dir/sub/file.txt", "/this/is/dir/sub/file.txt", "name=[path][name].[ext]"); test("dir/sub/file.txt", "/this/is/dir/sub/file.txt", "name=[path][name].[ext]&context=/this/is"); }); it("should process hash correctly", function() { test("d93591bdf7860e1e4ee2fca799911215.txt", "/file.txt", "", new Buffer("4321")); }); it("should process hash options correctly", function() { test("81dc9.txt", "/file.txt", "name=[hash:5].[ext]"); test("d4045.txt", "/file.txt", "name=[sha512:hash:5].[ext]"); test("1lQ3UNSdIS0c9dQ5brCZO1.txt", "/file.txt", "name=[hash:base64].[ext]"); test("caYJDUvUOiGAdDsiHKffIEj.txt", "/file.txt", "name=[hash:base52].[ext]"); test("sntmopgidsdqrofkjywoyldtiij.txt", "/file.txt", "name=[hash:base26].[ext]"); test("sntmopgids.txt", "/file.txt", "name=[hash:base26:10].[ext]"); }); }); describe("publicPath option", function() { it("should be supported", function() { run("/file.txt", "publicPath=http://cdn/").result.should.be.eql( 'module.exports = "http://cdn/81dc9bdb52d04dc20036dbd8313ed055.txt";' ); }); it("should override public path when given empty string", function() { run("file.txt", "publicPath=").result.should.be.eql( 'module.exports = "81dc9bdb52d04dc20036dbd8313ed055.txt";' ); }); it("should use webpack public path when not set", function() { run("file.txt").result.should.be.eql( 'module.exports = __webpack_public_path__ + "81dc9bdb52d04dc20036dbd8313ed055.txt";' ); }); }); describe("useRelativePath option", function() { it("should be supported", function() { run("/this/is/the/context/file.txt", "useRelativePath=true").result.should.be.eql( 'module.exports = __webpack_public_path__ + \"./81dc9bdb52d04dc20036dbd8313ed055.txt\";' ); run("/this/is/file.txt", "useRelativePath=true").result.should.be.eql( 'module.exports = __webpack_public_path__ + \"../../81dc9bdb52d04dc20036dbd8313ed055.txt\";' ); run("/this/file.txt", "context=/this/is/the/&useRelativePath=true").result.should.be.eql( 'module.exports = __webpack_public_path__ + \"../../81dc9bdb52d04dc20036dbd8313ed055.txt\";' ); run("/this/file.txt", "context=/&useRelativePath=true").result.should.be.eql( 'module.exports = __webpack_public_path__ + \"this/81dc9bdb52d04dc20036dbd8313ed055.txt\";' ); }); }); describe("outputPath function", function() { it("should be supported", function() { outputFunc = function(value) { return("/path/set/by/func"); }; var options = {}; options.outputPath = outputFunc; run_with_options("/this/is/the/context/file.txt", options).result.should.be.eql( 'module.exports = __webpack_public_path__ + \"/path/set/by/func\";' ); }); it("should be ignored if you set useRelativePath", function() { outputFunc = function(value) { return("/path/set/by/func"); }; var options = {}; options.outputPath = outputFunc; options.useRelativePath = true; run_with_options("/this/is/the/context/file.txt", options).result.should.be.eql( 'module.exports = __webpack_public_path__ + \"./81dc9bdb52d04dc20036dbd8313ed055.txt\";' ); }); }); file-loader-0.11.2/test/optional-file-emission.test.js000066400000000000000000000012451311520532300226340ustar00rootroot00000000000000var should = require("should"); var fileLoader = require("../"); function run(resourcePath, query, content) { content = content || new Buffer("1234"); var result = false; var context = { resourcePath: resourcePath, query: "?" + query, options: { context: "/this/is/the/context" }, emitFile: function(url, content2) { result = true; } }; fileLoader.call(context, content); return result; } describe("optional-emission", function() { it("should emit a file by default", function() { run("whatever.txt", "").should.be.true; }); it("should not emit a file if disabled", function() { run("whatever.txt", "emitFile=false").should.be.false; }); });