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/file-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.9.0
Choose a base ref
...
head repository: webpack-contrib/file-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.10.0
Choose a head ref
  • 11 commits
  • 9 files changed
  • 5 contributors

Commits on Nov 16, 2016

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    9fdd47e View commit details

Commits on Jan 28, 2017

  1. chore(issues): add issue templates

    SpaceK33z authored and joshwiens committed Jan 28, 2017

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    0727efe View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6833c70 View commit details
  3. Copy the full SHA
    1462d4b View commit details
  4. Copy the full SHA
    b5ea427 View commit details
  5. Copy the full SHA
    3e5985a View commit details
  6. Copy the full SHA
    6fec719 View commit details
  7. docs(readme): fix icon url

    joshwiens committed Jan 28, 2017
    Copy the full SHA
    eaeaa0e View commit details
  8. Copy the full SHA
    d82e8de View commit details
  9. Copy the full SHA
    ba2e876 View commit details
  10. chore(release): 0.10.0

    joshwiens committed Jan 28, 2017
    Copy the full SHA
    2d239df View commit details
Showing with 245 additions and 34 deletions.
  1. +15 −0 .github/ISSUE_TEMPLATE.md
  2. +18 −0 .github/PULL_REQUEST_TEMPLATE.md
  3. +36 −0 .github/assets/file_loader_icon.svg
  4. +28 −3 .travis.yml
  5. +17 −0 CHANGELOG.md
  6. +20 −0 LICENSE
  7. +94 −26 README.md
  8. +12 −3 index.js
  9. +5 −2 package.json
15 changes: 15 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Before creating an issue please make sure you are using the latest version of file-loader. -->

**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.**
18 changes: 18 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- 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**
36 changes: 36 additions & 0 deletions .github/assets/file_loader_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 28 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
sudo: false
language: node_js
node_js:
- "0.10"
- "0.11"
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)
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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.

<a name="0.10.0"></a>
# [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.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 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.
120 changes: 94 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,57 @@
# file loader for webpack
[![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://webpack.js.org/assets/icon-square-big.svg">
</a>
<h1>File Loader</h1>
</div>

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

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

## Usage
<h2 align="center">Usage</h2>

[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
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!./file.png");
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 the filename of the resulting file is the MD5 hash of the file's contents
with the original extension of the required resource.

By default a file is emitted, however this can be disabled if required (e.g. for server
side packages).

``` javascript
var url = require("file?emitFile=false!./file.png");
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
#### 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]`.

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` and `publicPath` query name parameters:

```
use: "file-loader?name=[name].[ext]&publicPath=assets/foo/&outputPath=app/images/"
```

### Filename template placeholders
#### Filename template placeholders

* `[ext]` the extension of the resource
* `[name]` the basename of the resource
@@ -41,37 +63,83 @@ use `?name=[path][name].[ext]`.
* and `length` the length in chars
* `[N]` the N-th match obtained from matching the current file name against the query param `regExp`

## Examples
#### Examples

``` javascript
require("file?name=js/[hash].script.[ext]!./javascript.js");
require("file-loader?name=js/[hash].script.[ext]!./javascript.js");
// => js/0dcbbaa701328a3c262cfd45869e351f.script.js

require("file?name=html-[hash:6].html!./page.html");
require("file-loader?name=html-[hash:6].html!./page.html");
// => html-109fa8.html

require("file?name=[hash]!./flash.txt");
require("file-loader?name=[hash]!./flash.txt");
// => c31e9820c001c9c4a86bce33ce43b679

require("file?name=[sha512:hash:base64:7].[ext]!./image.png");
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?name=img-[sha512:hash:base64:7].[ext]!./image.jpg");
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?name=picture.png!./myself.png");
require("file-loader?name=picture.png!./myself.png");
// => picture.png

require("file?name=[path][name].[ext]?[hash]!./dir/file.png")
require("file-loader?name=[path][name].[ext]?[hash]!./dir/file.png")
// => dir/file.png?e43b20c069c4a01867c31e98cbce33c9
```

## Installation
<h2 align="center">Contributing</h2>

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

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

<table>
<tbody>
<tr>
<td align="center">
<img width="150" height="150"
src="https://avatars.githubusercontent.com/sokra?v=3">
<br />
<a href="https://github.com/">Tobias Koppers</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars.githubusercontent.com/SpaceK33z?v=3">
<br />
<a href="https://github.com/">Kees Kluskens</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars.githubusercontent.com/mobitar?v=3">
<br />
<a href="https://github.com/">Mo Bitar</a>
</td>
</tr>
</tbody>
</table>


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

#### [MIT](./LICENSE)

[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

```npm install file-loader --save-dev```
[tests]: http://img.shields.io/travis/webpack-contrib/file-loader.svg
[tests-url]: https://travis-ci.org/webpack-contrib/file-loader

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

MIT (http://www.opensource.org/licenses/mit-license.php)
[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -33,19 +33,28 @@ module.exports = function(content) {
regExp: config.regExp
});

var outputPath = url;

var publicPath = "__webpack_public_path__ + " + JSON.stringify(url);

if (config.outputPath) {
// support functions as outputPath to generate them dynamically
outputPath = typeof config.outputPath === "function"
? config.outputPath(url)
: config.outputPath + url
}

if (config.publicPath) {
// support functions as publicPath to generate them dynamically
publicPath = JSON.stringify(
typeof config.publicPath === "function"
? config.publicPath(url)
typeof config.publicPath === "function"
? config.publicPath(url)
: config.publicPath + url
);
}

if (query.emitFile === undefined || query.emitFile) {
this.emitFile(url, content);
this.emitFile(outputPath, content);
}

return "module.exports = " + publicPath + ";";
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "file-loader",
"version": "0.9.0",
"version": "0.10.0",
"author": "Tobias Koppers @sokra",
"description": "file loader module for webpack",
"files": [
@@ -11,10 +11,13 @@
},
"devDependencies": {
"should": "~4.0.4",
"standard-version": "^4.0.0",
"mocha": "~1.21.3"
},
"scripts": {
"test": "mocha -R spec"
"test": "mocha -R spec",
"travis:test": "npm run test",
"release": "standard-version"
},
"repository": {
"type": "git",