Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
chore(*): project standardization updates for v2 (#349)
Browse files Browse the repository at this point in the history
* docs(logo): add logo

* docs(README): refactor for webpack v2

* ci(travis): add node v6

* chore(package): add engines, update dependencies

* docs(LICENSE): add JSF license

* chore(.github): add ISSUE && PULL_REQUEST_TEMPLATE
  • Loading branch information
michael-ciniawsky authored and joshwiens committed Jan 26, 2017
1 parent 74b86e0 commit 69dfd40
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 79 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1. Check the version of package you are using. If it's not the newest version, update and try again (see changelog while updating!).
2. If the issue is still there, write a minimal project showing the problem and expected output.
3. Link to the project and mention Node version and OS in your report.

**IMPORTANT! You should use [Stack Overflow](https://stackoverflow.com/) for support related questions.**
4 changes: 4 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1. [Read and sign the CLA](https://cla.js.foundation/webpack/webpack.js.org). This needs to be done only once. PRs that haven't signed it won't be accepted.
2. Make sure your PR complies with [the writer's guide](https://webpack.js.org/writers-guide/).
3. Read through the PR diff carefully as sometimes this can reveal issues. The work will be reviewed, but this can save some effort.
4. Remove these instructions from your PR as they are for your eyes only.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
sudo: false
language: node_js
node_js:
- "4"
- node
- 6
- 4
script: npm run travis

after_success:
Expand Down
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.
188 changes: 118 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,117 @@
# extract text plugin for webpack 2

The API has changed since version 1. For the webpack 1 version, see [the README in the webpack-1 branch](https://github.com/webpack/extract-text-webpack-plugin/blob/webpack-1/README.md).

## Install

> You can either install it with [npm](https://nodejs.org/en/) or [yarn](https://yarnpkg.com/)
```sh
[![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">
<img width="200" height="200"
src="https://webpack.github.io/extract-text-webpack-plugin/logo.svg">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200"
src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
<h1>Extract Text Plugin</h1>
</div>

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

```bash
npm install --save-dev extract-text-webpack-plugin
```
or
```sh
yarn add --dev extract-text-webpack-plugin
```

## Usage example with css
<h2 align="center">Usage</h2>

> :warning: For webpack v1, see [the README in the webpack-1 branch](https://github.com/webpack/extract-text-webpack-plugin/blob/webpack-1/README.md).
```js
const ExtractTextPlugin = require("extract-text-webpack-plugin");

``` javascript
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
module: {
loaders: [
{ test: /\.css$/, loader: ExtractTextPlugin.extract({
fallbackLoader: "style-loader",
loader: "css-loader"
}) }
]
},
plugins: [
new ExtractTextPlugin("styles.css")
]
module: {
rules: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: "style-loader",
loader: "css-loader"
})
}
]
},
plugins: [
new ExtractTextPlugin("styles.css");
]
}
```

It moves every `require("style.css")` in entry chunks into a separate css output file. So your styles are no longer inlined into the javascript, but separate in a css bundle file (`styles.css`). If your total stylesheet volume is big, it will be faster because the stylesheet bundle is loaded in parallel to the javascript bundle.

Advantages:
It moves every `require("style.css")` in entry chunks into a separate CSS file. So your styles are no longer inlined into the JS bundle, but separate in a CSS bundle file (`styles.css`). If your total stylesheet volume is big, it will be faster because the CSS bundle is loaded in parallel to the JS bundle.

* Fewer style tags (older IE has a limit)
* CSS SourceMap (with `devtool: "source-map"` and `css-loader?sourceMap`)
* CSS requested in parallel
* CSS cached separate
* Faster runtime (less code and DOM operations)
|Advantages|Caveats|
|:---------|:------|
| Fewer style tags (older IE has a limit) | Additional HTTP request |
| CSS SourceMap (with `devtool: "source-map"` and `extract-text-webpack-plugin?sourceMap`) | Longer compilation time |
| CSS requested in parallel | No runtime public path modification |
| CSS cached separate | No Hot Module Replacement |
| Faster runtime (less code and DOM operations) | ... |

Caveats:
<h2 align="center">Options</h2>

* Additional HTTP request
* Longer compilation time
* More complex configuration
* No runtime public path modification
* No Hot Module Replacement

## API

``` javascript
```js
new ExtractTextPlugin(options: filename | object)
```

* `options.filename: string` _(required)_ the filename of the result file. May contain `[name]`, `[id]` and `[contenthash]`
* `[name]` the name of the chunk
* `[id]` the number of the chunk
* `[contenthash]` a hash of the content of the extracted file
* `options.allChunks: boolean` extract from all additional chunks too (by default it extracts only from the initial chunk(s))
* `options.disable: boolean` disables the plugin
* `options.id: string` Unique ident for this plugin instance. (For advanced usage only, by default automatically generated)
|Name|Type|Description|
|:--:|:--:|:----------|
|**`id`**|`{String}`|Unique ident for this plugin instance. (For advanced usage only, by default automatically generated)|
|**`filename`**|`{String}`|Name of the result file. May contain `[name]`, `[id]` and `[contenthash]`|
|**`options.allChunks`**|`{Boolean}`|Extract from all additional chunks too (by default it extracts only from the initial chunk(s))|
|**`options.disable`**|`{Boolean}`|Disables the plugin|

* `[name]` name of the chunk
* `[id]` number of the chunk
* `[contenthash]` hash of the content of the extracted file

> :warning: `ExtractTextPlugin` generates a file **per entry**, so you must use `[name]`, `[id]` or `[contenthash]` when using multiple entries.
The `ExtractTextPlugin` generates an output file per entry, so you must use `[name]`, `[id]` or `[contenthash]` when using multiple entries.
#### `#extract`

``` javascript
```js
ExtractTextPlugin.extract(options: loader | object)
```

Creates an extracting loader from an existing loader. Supports loaders of type `{ loader: string; query: object }`.

* `options.loader: string | object | loader[]` _(required)_ the loader(s) that should be used for converting the resource to a css exporting module
* `options.fallbackLoader: string | object | loader[]` the loader(s) that should be used when the css is not extracted (i.e. in an additional chunk when `allChunks: false`)
* `options.publicPath: string` override the `publicPath` setting for this loader
|Name|Type|Description|
|:--:|:--:|:----------|
|**`options.loader`**|`{String}`/`{Object}`|Loader(s) that should be used for converting the resource to a CSS exporting module _(required)_|
|**`options.fallbackLoader`**|`{String}`/`{Object}`|loader(e.g `'style-loader'`) that should be used when the CSS is not extracted (i.e. in an additional chunk when `allChunks: false`)|
|**`options.publicPath`**|`{String}`|Override the `publicPath` setting for this loader|

There is also an `extract` function on the instance. You should use this if you have more than one `ExtractTextPlugin`.

```javascript
let ExtractTextPlugin = require('extract-text-webpack-plugin');
#### Multiple Instances

// multiple extract instances
let extractCSS = new ExtractTextPlugin('stylesheets/[name].css');
let extractLESS = new ExtractTextPlugin('stylesheets/[name].less');
There is also an `extract` function on the instance. You should use this if you have more than one instance of `ExtractTextPlugin`.

```js
const ExtractTextPlugin = require('extract-text-webpack-plugin');

// Create multiple instances
const extractCSS = new ExtractTextPlugin('stylesheets/[name].css');
const extractLESS = new ExtractTextPlugin('stylesheets/[name].less');

module.exports = {
...
module: {
loaders: [
{ test: /\.scss$/i, loader: extractCSS.extract(['css-loader','sass-loader']) },
{ test: /\.less$/i, loader: extractLESS.extract(['css-loader','less-loader']) },
...
use: [
{
test: /\.css$/,
loader: extractCSS.extract([ 'css-loader', 'postcss-loader' ])
},
{
test: /\.html$/i,

This comment has been minimized.

Copy link
@sunstorymvp

sunstorymvp Jan 29, 2017

seems like .html should be replaced with .less

loader: extractLESS.extract([ 'css-loader', 'less-loader' ])
},
]
},
plugins: [
Expand All @@ -102,6 +121,35 @@ module.exports = {
};
```

## License
<h2 align="center">Maintainer</h2>

<table>
<tbody>
<tr>
<td align="center">
<img width="150 height="150" src="https://github.com/sokra.png?s=150">
<br>
<a href="https://github.com/sokra">Tobias Koppers</a>
</td>
<tr>
<tbody>
</table>


[npm]: https://img.shields.io/npm/v/extract-text-webpack-plugin.svg
[npm-url]: https://npmjs.com/package/extract-text-webpack-plugin

[node]: https://img.shields.io/node/v/extract-text-webpack-plugin.svg
[node-url]: https://nodejs.org

[deps]: https://david-dm.org/webpack/extract-text-webpack-plugin.svg
[deps-url]: https://david-dm.org/webpack/extract-text-webpack-plugin

[tests]: http://img.shields.io/travis/webpack/extract-text-webpack-plugin.svg
[tests-url]: https://travis-ci.org/webpack/extract-text-webpack-plugin

[cover]: https://coveralls.io/repos/github/webpack/extract-text-webpack-plugin/badge.svg
[cover-url]: https://coveralls.io/github/webpack/extract-text-webpack-plugin

MIT (http://www.opensource.org/licenses/mit-license.php)
[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack
4 changes: 4 additions & 0 deletions logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"version": "2.0.0-beta.5",
"author": "Tobias Koppers @sokra",
"description": "Extract text from bundle into a file.",
"engines": { "node": ">=4.3.0 < 5.0.0 || >= 5.10" },
"peerDependencies": {
"webpack": "^2.1.0-beta.19 || ^2.2.0-rc.0"
"webpack": "^2.2.0"
},
"dependencies": {
"async": "^2.1.2",
Expand All @@ -14,15 +15,15 @@
"devDependencies": {
"codecov.io": "^0.1.2",
"coveralls": "^2.11.2",
"css-loader": "^0.21.0",
"file-loader": "^0.8.4",
"istanbul": "^0.3.13",
"mocha": "^2.3.3",
"mocha-lcov-reporter": "0.0.2",
"css-loader": "^0.26.1",
"file-loader": "^0.9.0",
"istanbul": "^0.4.5",
"mocha": "^3.2.0",
"mocha-lcov-reporter": "1.2.0",
"raw-loader": "^0.5.1",
"should": "^7.1.1",
"should": "^11.1.2",
"style-loader": "^0.13.0",
"webpack": "^2.1.0-beta"
"webpack": "^2.2.0"
},
"homepage": "http://github.com/webpack/extract-text-webpack-plugin",
"repository": {
Expand Down

0 comments on commit 69dfd40

Please sign in to comment.