Skip to content

Commit 839687b

Browse files
committed
upgrade to 2.x
2 parents 1411ae0 + a5729c7 commit 839687b

File tree

34 files changed

+355
-209
lines changed

34 files changed

+355
-209
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/node_modules
2+
23
/example/assets
3-
/test/js
44

5+
/test/js
56
/coverage
7+
8+
/.idea

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- "0.12"
4+
- "4"
55
- node
66
script: npm run travis
77

README.md

+41-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
# extract text plugin for webpack
1+
# extract text plugin for webpack 2
2+
3+
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).
4+
5+
## Install
6+
7+
> You can either install it with [npm](https://nodejs.org/en/) or [yarn](https://yarnpkg.com/)
8+
9+
```sh
10+
npm install --save-dev extract-text-webpack-plugin
11+
```
12+
or
13+
```sh
14+
yarn add --dev extract-text-webpack-plugin
15+
```
216

317
## Usage example with css
418

@@ -7,7 +21,10 @@ var ExtractTextPlugin = require("extract-text-webpack-plugin");
721
module.exports = {
822
module: {
923
loaders: [
10-
{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }
24+
{ test: /\.css$/, loader: ExtractTextPlugin.extract({
25+
fallbackLoader: "style-loader",
26+
loader: "css-loader"
27+
}) }
1128
]
1229
},
1330
plugins: [
@@ -37,42 +54,39 @@ Caveats:
3754
## API
3855

3956
``` javascript
40-
new ExtractTextPlugin([id: string], filename: string, [options])
57+
new ExtractTextPlugin(options: filename | object)
4158
```
4259

43-
* `id` Unique ident for this plugin instance. (For advanced usage only; by default, automatically generated)
44-
* `filename` the filename of the result file. May contain `[name]`, `[id]` and `[contenthash]`.
60+
* `options.filename: string` _(required)_ the filename of the result file. May contain `[name]`, `[id]` and `[contenthash]`
4561
* `[name]` the name of the chunk
4662
* `[id]` the number of the chunk
4763
* `[contenthash]` a hash of the content of the extracted file
48-
* `options`
49-
* `allChunks` extract from all additional chunks too (by default it extracts only from the initial chunk(s))
50-
* `disable` disables the plugin
51-
* `filenamefilter` function to modify path and filename before files are emitted
52-
53-
```
54-
{
55-
filenamefilter: function(filename) {
56-
// modify filename
57-
return filename;
58-
}
59-
}
60-
```
64+
* `options.allChunks: boolean` extract from all additional chunks too (by default it extracts only from the initial chunk(s))
65+
* `options.disable: boolean` disables the plugin
66+
* `options.id: string` Unique ident for this plugin instance. (For advanced usage only, by default automatically generated)
67+
* `filenamefilter` function to modify path and filename before files are emitted
68+
```
69+
{
70+
filenamefilter: function(filename) {
71+
// modify filename
72+
return filename;
73+
}
74+
}
75+
```
6176

6277
The `ExtractTextPlugin` generates an output file per entry, so you must use `[name]`, `[id]` or `[contenthash]` when using multiple entries.
6378

6479
``` javascript
65-
ExtractTextPlugin.extract([notExtractLoader], loader, [options])
80+
ExtractTextPlugin.extract(options: loader | object)
6681
```
6782

68-
Creates an extracting loader from an existing loader.
83+
Creates an extracting loader from an existing loader. Supports loaders of type `{ loader: string; query: object }`.
6984

70-
* `notExtractLoader` (optional) the loader(s) that should be used when the css is not extracted (i.e. in an additional chunk when `allChunks: false`)
71-
* `loader` the loader(s) that should be used for converting the resource to a css exporting module.
72-
* `options`
73-
* `publicPath` override the `publicPath` setting for this loader.
85+
* `options.loader: string | object | loader[]` _(required)_ the loader(s) that should be used for converting the resource to a css exporting module
86+
* `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`)
87+
* `options.publicPath: string` override the `publicPath` setting for this loader
7488

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

7791
```javascript
7892
let ExtractTextPlugin = require('extract-text-webpack-plugin');
@@ -85,8 +99,8 @@ module.exports = {
8599
...
86100
module: {
87101
loaders: [
88-
{test: /\.scss$/i, loader: extractCSS.extract(['css','sass'])},
89-
{test: /\.less$/i, loader: extractLESS.extract(['css','less'])},
102+
{ test: /\.scss$/i, loader: extractCSS.extract(['css-loader','sass-loader']) },
103+
{ test: /\.less$/i, loader: extractLESS.extract(['css-loader','less-loader']) },
90104
...
91105
]
92106
},

example/webpack.config.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,21 @@ module.exports = {
1313
},
1414
module: {
1515
loaders: [
16-
{ test: /\.css$/, loader: ExtractTextPlugin.extract(
17-
"style-loader",
18-
"css-loader?sourceMap",
19-
{
20-
publicPath: "../"
21-
}
22-
)},
16+
{ test: /\.css$/, loader: ExtractTextPlugin.extract({
17+
notExtractLoader: "style-loader",
18+
loader: "css-loader?sourceMap",
19+
publicPath: "../"
20+
}) },
2321
{ test: /\.png$/, loader: "file-loader" }
2422
]
2523
},
2624
devtool: "source-map",
2725
plugins: [
28-
new ExtractTextPlugin("css/[name].css?[hash]-[chunkhash]-[contenthash]-[name]", {
26+
new ExtractTextPlugin({
27+
filename: "css/[name].css?[hash]-[chunkhash]-[contenthash]-[name]",
2928
disable: false,
3029
allChunks: true
3130
}),
32-
new webpack.optimize.CommonsChunkPlugin("c", "c.js")
31+
new webpack.optimize.CommonsChunkPlugin({ name: "c", filename: "c.js" })
3332
]
3433
};

0 commit comments

Comments
 (0)