chushihua
This commit is contained in:
+202
@@ -0,0 +1,202 @@
|
||||
# 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="3.0.2"></a>
|
||||
## [3.0.2](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.1...v3.0.2) (2017-10-25)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* refer to the `entrypoint` instead of the first `module` (`module.identifier`) ([#601](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/601)) ([d5a1de2](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/d5a1de2))
|
||||
|
||||
|
||||
|
||||
<a name="3.0.1"></a>
|
||||
## [3.0.1](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0...v3.0.1) (2017-10-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **index:** stricter check for `shouldExtract !== wasExtracted` ([#605](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/605)) ([510704f](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/510704f))
|
||||
* get real path from `__filename` instead of `__dirname` (`NS`) ([8de6558](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/8de6558))
|
||||
|
||||
|
||||
|
||||
<a name="3.0.0"></a>
|
||||
# [3.0.0](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v2.1.2...v3.0.0) (2017-07-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add missing `options.ignoreOrder` details in Error message ([#539](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/539)) ([dd43832](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/dd43832))
|
||||
|
||||
|
||||
### Code Refactoring
|
||||
|
||||
* Apply webpack-defaults & webpack 3.x support ([#540](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/540)) ([7ae32d9](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/7ae32d9))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* Enforces `engines` of `"node": ">=4.3.0 < 5.0.0 || >= 5.10`
|
||||
|
||||
- refactor: DeprecationWarning: Chunk.modules [543](https://github.com/webpack-contrib/extract-text-webpack-plugin/pull/543)
|
||||
* Updates to `Chunk.mapModules`. This release is not backwards compatible with `Webpack 2.x` due to breaking changes in webpack/webpack#4764
|
||||
|
||||
- fix: css generation order issue see: webpack/webpack#5225
|
||||
* Enforces `peerDependencies` of `"webpack": "^3.1.0"`.
|
||||
|
||||
|
||||
|
||||
<a name="3.0.0-rc.2"></a>
|
||||
# [3.0.0-rc.2](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-rc.1...v3.0.0-rc.2) (2017-07-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Modules shouldn't be passed to sort ([#568](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/568)) ([113cabb](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/113cabb))
|
||||
|
||||
|
||||
|
||||
<a name="3.0.0-rc.1"></a>
|
||||
# [3.0.0-rc.1](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-rc.0...v3.0.0-rc.1) (2017-07-07)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Module sorting ([27e3a28](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/27e3a28))
|
||||
|
||||
|
||||
|
||||
<a name="3.0.0-rc.0"></a>
|
||||
# [3.0.0-rc.0](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-beta.3...v3.0.0-rc.0) (2017-07-07)
|
||||
|
||||
|
||||
### Code Refactoring
|
||||
|
||||
* Update deprecated `chunk.modules` functions ([#553](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/553)) ([be7936d](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/be7936d))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* Updates to `Chunk.mapModules | forEachModule | getNumberOfModules`. This release is not backwards compatible with `Webpack 2.x` due to breaking changes in webpack/webpack#4764
|
||||
|
||||
|
||||
|
||||
<a name="3.0.0-beta.3"></a>
|
||||
# [3.0.0-beta.3](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2017-06-24)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Distribute schema with package ([5d0c28f](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/5d0c28f))
|
||||
|
||||
|
||||
<a name="3.0.0-beta.2"></a>
|
||||
# [3.0.0-beta.2](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2017-06-24)
|
||||
|
||||
* Skipped due to deployment issues with schema
|
||||
|
||||
<a name="3.0.0-beta.1"></a>
|
||||
# [3.0.0-beta.1](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v3.0.0-beta.0...v3.0.0-beta.1) (2017-06-24)
|
||||
|
||||
|
||||
* Skipped due to deployment issues with schema
|
||||
|
||||
|
||||
<a name="3.0.0-beta.0"></a>
|
||||
# [3.0.0-beta.0](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v2.1.2...v3.0.0-beta.0) (2017-06-23)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add missing `options.ignoreOrder` details in Error message ([#539](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/539)) ([dd43832](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/dd43832))
|
||||
|
||||
|
||||
### Code Refactoring
|
||||
|
||||
* Apply webpack-defaults ([#542](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/542)) ([292e217](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/292e217))
|
||||
* Chunk.modules deprecation warning ([28171b2](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/28171b2))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* Updates to `Chunk.mapModules`. This release is not backwards compatible with `Webpack 2.x` due to breaking changes in webpack/webpack#4764
|
||||
* Enforces `peerDependencies` of `"webpack": ">= 3.0.0-rc.0 || ^3.0.0"`.
|
||||
* Enforces `engines` of `"node": ">=4.3.0 < 5.0.0 || >= 5.10`
|
||||
|
||||
|
||||
|
||||
<a name="2.1.2"></a>
|
||||
## [2.1.2](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v2.1.1...v2.1.2) (2017-06-08)
|
||||
|
||||
|
||||
|
||||
<a name="2.1.1"></a>
|
||||
## [2.1.1](https://github.com/webpack-contrib/extract-text-webpack-plugin/compare/v2.1.0...v2.1.1) (2017-06-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add a not null check for the content property before throwing error ([#404](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/404)) ([58dd5d3](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/58dd5d3))
|
||||
* **loader:** rm unnecessary `this.cacheable` (caching) ([#530](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/530)) ([c3cb091](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/c3cb091))
|
||||
* don't extract from common async chunks ([#508](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/508)) ([e595417](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/e595417))
|
||||
* validation schema (`schema-utils`) ([#527](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/527)) ([dfeb347](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/dfeb347))
|
||||
|
||||
|
||||
|
||||
<a name="2.1.0"></a>
|
||||
# [2.1.0](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0...v2.1.0) (2017-03-05)
|
||||
|
||||
### Features
|
||||
|
||||
* The plugin **filename** accepts a function now. [c9a19ad](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/c9a19ad), closes [#423](https://github.com/webpack-contrib/extract-text-webpack-plugin/pull/423)
|
||||
|
||||
<a name="2.0.0"></a>
|
||||
# [2.0.0](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-rc.3...v2.0.0) (2017-02-24)
|
||||
|
||||
<a name="2.0.0-rc.2"></a>
|
||||
# [2.0.0-rc.2](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-rc.1...v2.0.0-rc.2) (2017-01-28)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **schema:** allow `extract` to accept omit/remove flags ([8ce93d5](https://github.com/webpack/extract-text-webpack-plugin/commit/8ce93d5)), closes [#371](https://github.com/webpack/extract-text-webpack-plugin/issues/371)
|
||||
* **schema:** connect loader schema with the code properly ([03bb4aa](https://github.com/webpack/extract-text-webpack-plugin/commit/03bb4aa))
|
||||
* **schema:** emit proper error messages ([70cbd4b](https://github.com/webpack/extract-text-webpack-plugin/commit/70cbd4b))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **errors:** show nicer errors if there are extra fields ([76a171d](https://github.com/webpack/extract-text-webpack-plugin/commit/76a171d))
|
||||
|
||||
|
||||
|
||||
<a name="2.0.0-rc.1"></a>
|
||||
# [2.0.0-rc.1](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-rc.0...v2.0.0-rc.1) (2017-01-28)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **options:** pass proper loader options to children ([#266](https://github.com/webpack/extract-text-webpack-plugin/issues/266)) ([6abf42d](https://github.com/webpack/extract-text-webpack-plugin/commit/6abf42d))
|
||||
|
||||
|
||||
|
||||
<a name="2.0.0-rc.0"></a>
|
||||
# [2.0.0-rc.0](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-beta.5...v2.0.0-rc.0) (2017-01-26)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **readme:** Incorrect loader configuration ([e477cc7](https://github.com/webpack/extract-text-webpack-plugin/commit/e477cc7))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **extract:** return an array of loader objects ([#343](https://github.com/webpack/extract-text-webpack-plugin/issues/343)) ([74b86e0](https://github.com/webpack/extract-text-webpack-plugin/commit/74b86e0))
|
||||
|
||||
|
||||
|
||||
# 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
@@ -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.
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
[![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://cdn.rawgit.com/webpack-contrib/extract-text-webpack-plugin/574e3200/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>
|
||||
<p>Extract text from a bundle, or bundles, into a separate file.</p>
|
||||
</div>
|
||||
|
||||
<h2 align="center">Install</h2>
|
||||
|
||||
```bash
|
||||
# for webpack 3
|
||||
npm install --save-dev extract-text-webpack-plugin
|
||||
# for webpack 2
|
||||
npm install --save-dev extract-text-webpack-plugin@2.1.2
|
||||
# for webpack 1
|
||||
npm install --save-dev extract-text-webpack-plugin@1.0.1
|
||||
```
|
||||
|
||||
<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");
|
||||
|
||||
module.exports = {
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ExtractTextPlugin.extract({
|
||||
fallback: "style-loader",
|
||||
use: "css-loader"
|
||||
})
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new ExtractTextPlugin("styles.css"),
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
It moves all the required `*.css` modules in entry chunks into a separate CSS file. So your styles are no longer inlined into the JS bundle, but in a separate CSS 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.
|
||||
|
||||
|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) | ... |
|
||||
|
||||
<h2 align="center">Options</h2>
|
||||
|
||||
```js
|
||||
new ExtractTextPlugin(options: filename | object)
|
||||
```
|
||||
|
||||
|Name|Type|Description|
|
||||
|:--:|:--:|:----------|
|
||||
|**`id`**|`{String}`|Unique ident for this plugin instance. (For advanced usage only, by default automatically generated)|
|
||||
|**`filename`**|`{String\|Function}`|Name of the result file. May contain `[name]`, `[id]` and `[contenthash]`|
|
||||
|**`allChunks`**|`{Boolean}`|Extract from all additional chunks too (by default it extracts only from the initial chunk(s))<br />When using `CommonsChunkPlugin` and there are extracted chunks (from `ExtractTextPlugin.extract`) in the commons chunk, `allChunks` **must** be set to `true`|
|
||||
|**`disable`**|`{Boolean}`|Disables the plugin|
|
||||
|**`ignoreOrder`**|`{Boolean}`|Disables order check (useful for CSS Modules!), `false` by default|
|
||||
|
||||
* `[name]` name of the chunk
|
||||
* `[id]` number of the chunk
|
||||
* `[contenthash]` hash of the content of the extracted file
|
||||
* `[<hashType>:contenthash:<digestType>:<length>]` optionally you can configure
|
||||
* other `hashType`s, e.g. `sha1`, `md5`, `sha256`, `sha512`
|
||||
* other `digestType`s, e.g. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
|
||||
* and `length`, the length of the hash in chars
|
||||
|
||||
> :warning: `ExtractTextPlugin` generates a file **per entry**, so you must use `[name]`, `[id]` or `[contenthash]` when using multiple entries.
|
||||
|
||||
#### `#extract`
|
||||
|
||||
```js
|
||||
ExtractTextPlugin.extract(options: loader | object)
|
||||
```
|
||||
|
||||
Creates an extracting loader from an existing loader. Supports loaders of type `{ loader: [name]-loader -> {String}, options: {} -> {Object} }`.
|
||||
|
||||
|Name|Type|Description|
|
||||
|:--:|:--:|:----------|
|
||||
|**`options.use`**|`{String}`/`{Array}`/`{Object}`|Loader(s) that should be used for converting the resource to a CSS exporting module _(required)_|
|
||||
|**`options.fallback`**|`{String}`/`{Array}`/`{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|
|
||||
|
||||
|
||||
#### Multiple Instances
|
||||
|
||||
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]-one.css');
|
||||
const extractLESS = new ExtractTextPlugin('stylesheets/[name]-two.css');
|
||||
|
||||
module.exports = {
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: extractCSS.extract([ 'css-loader', 'postcss-loader' ])
|
||||
},
|
||||
{
|
||||
test: /\.less$/i,
|
||||
use: extractLESS.extract([ 'css-loader', 'less-loader' ])
|
||||
},
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
extractCSS,
|
||||
extractLESS
|
||||
]
|
||||
};
|
||||
```
|
||||
|
||||
### Extracting Sass or LESS
|
||||
|
||||
The configuration is the same, switch out `sass-loader` for `less-loader` when necessary.
|
||||
|
||||
```js
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: ExtractTextPlugin.extract({
|
||||
fallback: 'style-loader',
|
||||
//resolve-url-loader may be chained before sass-loader if necessary
|
||||
use: ['css-loader', 'sass-loader']
|
||||
})
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new ExtractTextPlugin('style.css')
|
||||
//if you want to pass in options, you can do so:
|
||||
//new ExtractTextPlugin({
|
||||
// filename: 'style.css'
|
||||
//})
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Modify filename
|
||||
|
||||
`filename` parameter could be `Function`. It passes `getPath` to process the format like `css/[name].css` and returns the real file name, `css/js/a.css`. You can replace `css/js` with `css` then you will get the new path `css/a.css`.
|
||||
|
||||
|
||||
```js
|
||||
entry: {
|
||||
'js/a': "./a"
|
||||
},
|
||||
plugins: [
|
||||
new ExtractTextPlugin({
|
||||
filename: (getPath) => {
|
||||
return getPath('css/[name].css').replace('css/js', 'css');
|
||||
},
|
||||
allChunks: true
|
||||
})
|
||||
]
|
||||
```
|
||||
|
||||
<h2 align="center">Maintainers</h2>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<img width="150" height="150"
|
||||
src="https://avatars3.githubusercontent.com/u/166921?v=3&s=150">
|
||||
</br>
|
||||
<a href="https://github.com/bebraw">Juho Vepsäläinen</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<img width="150" height="150"
|
||||
src="https://avatars2.githubusercontent.com/u/8420490?v=3&s=150">
|
||||
</br>
|
||||
<a href="https://github.com/d3viant0ne">Joshua Wiens</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<img width="150" height="150"
|
||||
src="https://avatars3.githubusercontent.com/u/533616?v=3&s=150">
|
||||
</br>
|
||||
<a href="https://github.com/SpaceK33z">Kees Kluskens</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<img width="150" height="150"
|
||||
src="https://avatars3.githubusercontent.com/u/3408176?v=3&s=150">
|
||||
</br>
|
||||
<a href="https://github.com/TheLarkInn">Sean Larkin</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-contrib/extract-text-webpack-plugin.svg
|
||||
[deps-url]: https://david-dm.org/webpack-contrib/extract-text-webpack-plugin
|
||||
|
||||
[tests]: http://img.shields.io/travis/webpack-contrib/extract-text-webpack-plugin.svg
|
||||
[tests-url]: https://travis-ci.org/webpack-contrib/extract-text-webpack-plugin
|
||||
|
||||
[cover]: https://coveralls.io/repos/github/webpack-contrib/extract-text-webpack-plugin/badge.svg
|
||||
[cover-url]: https://coveralls.io/github/webpack-contrib/extract-text-webpack-plugin
|
||||
|
||||
[chat]: https://badges.gitter.im/webpack/webpack.svg
|
||||
[chat-url]: https://gitter.im/webpack/webpack
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./index').default;
|
||||
+291
@@ -0,0 +1,291 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _fs = require('fs');
|
||||
|
||||
var _fs2 = _interopRequireDefault(_fs);
|
||||
|
||||
var _path = require('path');
|
||||
|
||||
var _path2 = _interopRequireDefault(_path);
|
||||
|
||||
var _Chunk = require('webpack/lib/Chunk');
|
||||
|
||||
var _Chunk2 = _interopRequireDefault(_Chunk);
|
||||
|
||||
var _webpackSources = require('webpack-sources');
|
||||
|
||||
var _async = require('async');
|
||||
|
||||
var _async2 = _interopRequireDefault(_async);
|
||||
|
||||
var _loaderUtils = require('loader-utils');
|
||||
|
||||
var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
|
||||
|
||||
var _schemaUtils = require('schema-utils');
|
||||
|
||||
var _schemaUtils2 = _interopRequireDefault(_schemaUtils);
|
||||
|
||||
var _ExtractTextPluginCompilation = require('./lib/ExtractTextPluginCompilation');
|
||||
|
||||
var _ExtractTextPluginCompilation2 = _interopRequireDefault(_ExtractTextPluginCompilation);
|
||||
|
||||
var _OrderUndefinedError = require('./lib/OrderUndefinedError');
|
||||
|
||||
var _OrderUndefinedError2 = _interopRequireDefault(_OrderUndefinedError);
|
||||
|
||||
var _helpers = require('./lib/helpers');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var NS = _path2.default.dirname(_fs2.default.realpathSync(__filename));
|
||||
|
||||
var nextId = 0;
|
||||
|
||||
var ExtractTextPlugin = function () {
|
||||
function ExtractTextPlugin(options) {
|
||||
_classCallCheck(this, ExtractTextPlugin);
|
||||
|
||||
if ((0, _helpers.isString)(options)) {
|
||||
options = { filename: options };
|
||||
} else {
|
||||
(0, _schemaUtils2.default)(_path2.default.resolve(__dirname, '../schema/plugin.json'), options, 'Extract Text Plugin');
|
||||
}
|
||||
this.filename = options.filename;
|
||||
this.id = options.id != null ? options.id : ++nextId;
|
||||
this.options = {};
|
||||
(0, _helpers.mergeOptions)(this.options, options);
|
||||
delete this.options.filename;
|
||||
delete this.options.id;
|
||||
}
|
||||
|
||||
_createClass(ExtractTextPlugin, [{
|
||||
key: 'applyAdditionalInformation',
|
||||
value: function applyAdditionalInformation(source, info) {
|
||||
if (info) {
|
||||
return new _webpackSources.ConcatSource(`@media ${info[0]} {`, source, '}');
|
||||
}
|
||||
return source;
|
||||
}
|
||||
}, {
|
||||
key: 'loader',
|
||||
value: function loader(options) {
|
||||
return ExtractTextPlugin.loader((0, _helpers.mergeOptions)({ id: this.id }, options));
|
||||
}
|
||||
}, {
|
||||
key: 'mergeNonInitialChunks',
|
||||
value: function mergeNonInitialChunks(chunk, intoChunk, checkedChunks) {
|
||||
var _this = this;
|
||||
|
||||
if (!intoChunk) {
|
||||
checkedChunks = [];
|
||||
chunk.chunks.forEach(function (c) {
|
||||
if ((0, _helpers.isInitialOrHasNoParents)(c)) return;
|
||||
_this.mergeNonInitialChunks(c, chunk, checkedChunks);
|
||||
}, this);
|
||||
} else if (checkedChunks.indexOf(chunk) < 0) {
|
||||
checkedChunks.push(chunk);
|
||||
chunk.forEachModule(function (module) {
|
||||
intoChunk.addModule(module);
|
||||
module.addChunk(intoChunk);
|
||||
});
|
||||
chunk.chunks.forEach(function (c) {
|
||||
if ((0, _helpers.isInitialOrHasNoParents)(c)) return;
|
||||
_this.mergeNonInitialChunks(c, intoChunk, checkedChunks);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'renderExtractedChunk',
|
||||
value: function renderExtractedChunk(chunk) {
|
||||
var _this2 = this;
|
||||
|
||||
var source = new _webpackSources.ConcatSource();
|
||||
chunk.forEachModule(function (module) {
|
||||
var moduleSource = module.source();
|
||||
source.add(_this2.applyAdditionalInformation(moduleSource, module.additionalInformation));
|
||||
}, this);
|
||||
return source;
|
||||
}
|
||||
}, {
|
||||
key: 'extract',
|
||||
value: function extract(options) {
|
||||
if (Array.isArray(options) || (0, _helpers.isString)(options) || typeof options.options === 'object' || typeof options.query === 'object') {
|
||||
options = { use: options };
|
||||
} else {
|
||||
(0, _schemaUtils2.default)(_path2.default.resolve(__dirname, '../schema/loader.json'), options, 'Extract Text Plugin (Loader)');
|
||||
}
|
||||
var loader = options.use;
|
||||
var before = options.fallback || [];
|
||||
if ((0, _helpers.isString)(loader)) {
|
||||
loader = loader.split('!');
|
||||
}
|
||||
if ((0, _helpers.isString)(before)) {
|
||||
before = before.split('!');
|
||||
} else if (!Array.isArray(before)) {
|
||||
before = [before];
|
||||
}
|
||||
options = (0, _helpers.mergeOptions)({ omit: before.length, remove: true }, options);
|
||||
delete options.use;
|
||||
delete options.fallback;
|
||||
return [this.loader(options)].concat(before, loader).map(_helpers.getLoaderObject);
|
||||
}
|
||||
}, {
|
||||
key: 'apply',
|
||||
value: function apply(compiler) {
|
||||
var _this3 = this;
|
||||
|
||||
var options = this.options;
|
||||
compiler.plugin('this-compilation', function (compilation) {
|
||||
var extractCompilation = new _ExtractTextPluginCompilation2.default();
|
||||
compilation.plugin('normal-module-loader', function (loaderContext, module) {
|
||||
loaderContext[NS] = function (content, opt) {
|
||||
if (options.disable) {
|
||||
return false;
|
||||
}
|
||||
if (!Array.isArray(content) && content != null) {
|
||||
throw new Error(`Exported value was not extracted as an array: ${JSON.stringify(content)}`);
|
||||
}
|
||||
module[NS] = {
|
||||
content,
|
||||
options: opt || {}
|
||||
};
|
||||
return options.allChunks || module[`${NS}/extract`]; // eslint-disable-line no-path-concat
|
||||
};
|
||||
});
|
||||
var filename = _this3.filename;
|
||||
var id = _this3.id;
|
||||
var extractedChunks = void 0;
|
||||
compilation.plugin('optimize-tree', function (chunks, modules, callback) {
|
||||
extractedChunks = chunks.map(function () {
|
||||
return new _Chunk2.default();
|
||||
});
|
||||
chunks.forEach(function (chunk, i) {
|
||||
var extractedChunk = extractedChunks[i];
|
||||
extractedChunk.index = i;
|
||||
extractedChunk.originalChunk = chunk;
|
||||
extractedChunk.name = chunk.name;
|
||||
extractedChunk.entrypoints = chunk.entrypoints;
|
||||
chunk.chunks.forEach(function (c) {
|
||||
extractedChunk.addChunk(extractedChunks[chunks.indexOf(c)]);
|
||||
});
|
||||
chunk.parents.forEach(function (c) {
|
||||
extractedChunk.addParent(extractedChunks[chunks.indexOf(c)]);
|
||||
});
|
||||
});
|
||||
_async2.default.forEach(chunks, function (chunk, callback) {
|
||||
// eslint-disable-line no-shadow
|
||||
var extractedChunk = extractedChunks[chunks.indexOf(chunk)];
|
||||
var shouldExtract = !!(options.allChunks || (0, _helpers.isInitialOrHasNoParents)(chunk));
|
||||
chunk.sortModules();
|
||||
_async2.default.forEach(chunk.mapModules(function (c) {
|
||||
return c;
|
||||
}), function (module, callback) {
|
||||
// eslint-disable-line no-shadow
|
||||
var meta = module[NS];
|
||||
if (meta && (!meta.options.id || meta.options.id === id)) {
|
||||
var wasExtracted = Array.isArray(meta.content);
|
||||
// A stricter `shouldExtract !== wasExtracted` check to guard against cases where a previously extracted
|
||||
// module would be extracted twice. Happens when a module is a dependency of an initial and a non-initial
|
||||
// chunk. See issue #604
|
||||
if (shouldExtract && !wasExtracted) {
|
||||
module[`${NS}/extract`] = shouldExtract; // eslint-disable-line no-path-concat
|
||||
compilation.rebuildModule(module, function (err) {
|
||||
if (err) {
|
||||
compilation.errors.push(err);
|
||||
return callback();
|
||||
}
|
||||
meta = module[NS];
|
||||
// Error out if content is not an array and is not null
|
||||
if (!Array.isArray(meta.content) && meta.content != null) {
|
||||
err = new Error(`${module.identifier()} doesn't export content`);
|
||||
compilation.errors.push(err);
|
||||
return callback();
|
||||
}
|
||||
if (meta.content) {
|
||||
extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk);
|
||||
}
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
if (meta.content) {
|
||||
extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk);
|
||||
}
|
||||
callback();
|
||||
}
|
||||
} else callback();
|
||||
}, function (err) {
|
||||
if (err) return callback(err);
|
||||
callback();
|
||||
});
|
||||
}, function (err) {
|
||||
if (err) return callback(err);
|
||||
extractedChunks.forEach(function (extractedChunk) {
|
||||
if ((0, _helpers.isInitialOrHasNoParents)(extractedChunk)) {
|
||||
_this3.mergeNonInitialChunks(extractedChunk);
|
||||
}
|
||||
}, _this3);
|
||||
extractedChunks.forEach(function (extractedChunk) {
|
||||
if (!(0, _helpers.isInitialOrHasNoParents)(extractedChunk)) {
|
||||
extractedChunk.forEachModule(function (module) {
|
||||
extractedChunk.removeModule(module);
|
||||
});
|
||||
}
|
||||
});
|
||||
compilation.applyPlugins('optimize-extracted-chunks', extractedChunks);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
compilation.plugin('additional-assets', function (callback) {
|
||||
extractedChunks.forEach(function (extractedChunk) {
|
||||
if (extractedChunk.getNumberOfModules()) {
|
||||
extractedChunk.sortModules(function (a, b) {
|
||||
if (!options.ignoreOrder && (0, _helpers.isInvalidOrder)(a, b)) {
|
||||
compilation.errors.push(new _OrderUndefinedError2.default(a.getOriginalModule()));
|
||||
compilation.errors.push(new _OrderUndefinedError2.default(b.getOriginalModule()));
|
||||
}
|
||||
return (0, _helpers.getOrder)(a, b);
|
||||
});
|
||||
var chunk = extractedChunk.originalChunk;
|
||||
var source = _this3.renderExtractedChunk(extractedChunk);
|
||||
|
||||
var getPath = function getPath(format) {
|
||||
return compilation.getPath(format, {
|
||||
chunk
|
||||
}).replace(/\[(?:(\w+):)?contenthash(?::([a-z]+\d*))?(?::(\d+))?\]/ig, function () {
|
||||
// eslint-disable-line func-names
|
||||
return _loaderUtils2.default.getHashDigest(source.source(), arguments[1], arguments[2], parseInt(arguments[3], 10));
|
||||
});
|
||||
};
|
||||
|
||||
var file = (0, _helpers.isFunction)(filename) ? filename(getPath) : getPath(filename);
|
||||
|
||||
compilation.assets[file] = source;
|
||||
chunk.files.push(file);
|
||||
}
|
||||
}, _this3);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
}], [{
|
||||
key: 'loader',
|
||||
value: function loader(options) {
|
||||
return { loader: require.resolve('./loader'), options };
|
||||
}
|
||||
}]);
|
||||
|
||||
return ExtractTextPlugin;
|
||||
}();
|
||||
|
||||
ExtractTextPlugin.extract = ExtractTextPlugin.prototype.extract.bind(ExtractTextPlugin);
|
||||
|
||||
exports.default = ExtractTextPlugin;
|
||||
Generated
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* eslint-disable no-multi-assign */
|
||||
|
||||
|
||||
var _ExtractedModule = require('./ExtractedModule');
|
||||
|
||||
var _ExtractedModule2 = _interopRequireDefault(_ExtractedModule);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var ExtractTextPluginCompilation = function () {
|
||||
function ExtractTextPluginCompilation() {
|
||||
_classCallCheck(this, ExtractTextPluginCompilation);
|
||||
|
||||
this.modulesByIdentifier = {};
|
||||
}
|
||||
|
||||
_createClass(ExtractTextPluginCompilation, [{
|
||||
key: 'addModule',
|
||||
value: function addModule(identifier, originalModule, source, additionalInformation, sourceMap, prevModules) {
|
||||
var m = void 0;
|
||||
if (!this.modulesByIdentifier[identifier]) {
|
||||
m = this.modulesByIdentifier[identifier] = new _ExtractedModule2.default(identifier, originalModule, source, sourceMap, additionalInformation, prevModules);
|
||||
} else {
|
||||
m = this.modulesByIdentifier[identifier];
|
||||
m.addPrevModules(prevModules);
|
||||
if (originalModule.index2 < m.getOriginalModule().index2) {
|
||||
m.setOriginalModule(originalModule);
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}, {
|
||||
key: 'addResultToChunk',
|
||||
value: function addResultToChunk(identifier, result, originalModule, extractedChunk) {
|
||||
var _this = this;
|
||||
|
||||
if (!Array.isArray(result)) {
|
||||
result = [[identifier, result]];
|
||||
}
|
||||
var counterMap = {};
|
||||
var prevModules = [];
|
||||
result.forEach(function (item) {
|
||||
var c = counterMap[item[0]];
|
||||
var module = _this.addModule.call(_this, item[0] + (c || ''), originalModule, item[1], item[2], item[3], prevModules.slice());
|
||||
extractedChunk.addModule(module);
|
||||
module.addChunk(extractedChunk);
|
||||
counterMap[item[0]] = (c || 0) + 1;
|
||||
prevModules.push(module);
|
||||
}, this);
|
||||
}
|
||||
}]);
|
||||
|
||||
return ExtractTextPluginCompilation;
|
||||
}();
|
||||
|
||||
exports.default = ExtractTextPluginCompilation;
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _webpackSources = require('webpack-sources');
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var ExtractedModule = function () {
|
||||
function ExtractedModule(identifier, originalModule, source, sourceMap, addtitionalInformation, prevModules) {
|
||||
_classCallCheck(this, ExtractedModule);
|
||||
|
||||
this._identifier = identifier;
|
||||
this._originalModule = originalModule;
|
||||
this._source = source;
|
||||
this._sourceMap = sourceMap;
|
||||
this._prevModules = prevModules;
|
||||
this.addtitionalInformation = addtitionalInformation;
|
||||
this.chunks = [];
|
||||
}
|
||||
|
||||
_createClass(ExtractedModule, [{
|
||||
key: 'getOrder',
|
||||
value: function getOrder() {
|
||||
// http://stackoverflow.com/a/14676665/1458162
|
||||
return (/^@import url/.test(this._source) ? 0 : 1
|
||||
);
|
||||
}
|
||||
}, {
|
||||
key: 'addChunk',
|
||||
value: function addChunk(chunk) {
|
||||
var idx = this.chunks.indexOf(chunk);
|
||||
if (idx < 0) {
|
||||
this.chunks.push(chunk);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'removeChunk',
|
||||
value: function removeChunk(chunk) {
|
||||
var idx = this.chunks.indexOf(chunk);
|
||||
if (idx >= 0) {
|
||||
this.chunks.splice(idx, 1);
|
||||
chunk.removeModule(this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, {
|
||||
key: 'rewriteChunkInReasons',
|
||||
value: function rewriteChunkInReasons(oldChunk, newChunks) {} // eslint-disable-line
|
||||
|
||||
}, {
|
||||
key: 'identifier',
|
||||
value: function identifier() {
|
||||
return this._identifier;
|
||||
}
|
||||
}, {
|
||||
key: 'source',
|
||||
value: function source() {
|
||||
if (this._sourceMap) {
|
||||
return new _webpackSources.SourceMapSource(this._source, null, this._sourceMap);
|
||||
}
|
||||
return new _webpackSources.RawSource(this._source);
|
||||
}
|
||||
}, {
|
||||
key: 'getOriginalModule',
|
||||
value: function getOriginalModule() {
|
||||
return this._originalModule;
|
||||
}
|
||||
}, {
|
||||
key: 'getPrevModules',
|
||||
value: function getPrevModules() {
|
||||
return this._prevModules;
|
||||
}
|
||||
}, {
|
||||
key: 'addPrevModules',
|
||||
value: function addPrevModules(prevModules) {
|
||||
var _this = this;
|
||||
|
||||
prevModules.forEach(function (m) {
|
||||
if (_this._prevModules.indexOf(m) < 0) {
|
||||
_this._prevModules.push(m);
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
}, {
|
||||
key: 'setOriginalModule',
|
||||
value: function setOriginalModule(originalModule) {
|
||||
this._originalModule = originalModule;
|
||||
}
|
||||
}]);
|
||||
|
||||
return ExtractedModule;
|
||||
}();
|
||||
|
||||
exports.default = ExtractedModule;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
function OrderUndefinedError(module) {
|
||||
Error.call(this);
|
||||
Error.captureStackTrace(this, OrderUndefinedError);
|
||||
this.name = 'OrderUndefinedError';
|
||||
this.message = 'Order in extracted chunk undefined';
|
||||
this.module = module;
|
||||
}
|
||||
exports.default = OrderUndefinedError;
|
||||
|
||||
|
||||
OrderUndefinedError.prototype = Object.create(Error.prototype);
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isInitialOrHasNoParents = isInitialOrHasNoParents;
|
||||
exports.isInvalidOrder = isInvalidOrder;
|
||||
exports.getOrder = getOrder;
|
||||
exports.getLoaderObject = getLoaderObject;
|
||||
exports.mergeOptions = mergeOptions;
|
||||
exports.isString = isString;
|
||||
exports.isFunction = isFunction;
|
||||
exports.isType = isType;
|
||||
function isInitialOrHasNoParents(chunk) {
|
||||
return chunk.isInitial() || chunk.parents.length === 0;
|
||||
}
|
||||
|
||||
function isInvalidOrder(a, b) {
|
||||
var bBeforeA = a.getPrevModules().indexOf(b) >= 0;
|
||||
var aBeforeB = b.getPrevModules().indexOf(a) >= 0;
|
||||
return aBeforeB && bBeforeA;
|
||||
}
|
||||
|
||||
function getOrder(a, b) {
|
||||
var aOrder = a.getOrder();
|
||||
var bOrder = b.getOrder();
|
||||
if (aOrder < bOrder) return -1;
|
||||
if (aOrder > bOrder) return 1;
|
||||
var aIndex = a.getOriginalModule().index2;
|
||||
var bIndex = b.getOriginalModule().index2;
|
||||
if (aIndex < bIndex) return -1;
|
||||
if (aIndex > bIndex) return 1;
|
||||
var bBeforeA = a.getPrevModules().indexOf(b) >= 0;
|
||||
var aBeforeB = b.getPrevModules().indexOf(a) >= 0;
|
||||
if (aBeforeB && !bBeforeA) return -1;
|
||||
if (!aBeforeB && bBeforeA) return 1;
|
||||
var ai = a.identifier();
|
||||
var bi = b.identifier();
|
||||
if (ai < bi) return -1;
|
||||
if (ai > bi) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getLoaderObject(loader) {
|
||||
if (isString(loader)) {
|
||||
return { loader };
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
||||
function mergeOptions(a, b) {
|
||||
if (!b) return a;
|
||||
Object.keys(b).forEach(function (key) {
|
||||
a[key] = b[key];
|
||||
});
|
||||
return a;
|
||||
}
|
||||
|
||||
function isString(a) {
|
||||
return typeof a === 'string';
|
||||
}
|
||||
|
||||
function isFunction(a) {
|
||||
return typeof a === 'function';
|
||||
}
|
||||
|
||||
function isType(type, obj) {
|
||||
return Object.prototype.toString.call(obj) === `[object ${type}]`;
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.pitch = pitch;
|
||||
|
||||
var _fs = require('fs');
|
||||
|
||||
var _fs2 = _interopRequireDefault(_fs);
|
||||
|
||||
var _path = require('path');
|
||||
|
||||
var _path2 = _interopRequireDefault(_path);
|
||||
|
||||
var _loaderUtils = require('loader-utils');
|
||||
|
||||
var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
|
||||
|
||||
var _NodeTemplatePlugin = require('webpack/lib/node/NodeTemplatePlugin');
|
||||
|
||||
var _NodeTemplatePlugin2 = _interopRequireDefault(_NodeTemplatePlugin);
|
||||
|
||||
var _NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin');
|
||||
|
||||
var _NodeTargetPlugin2 = _interopRequireDefault(_NodeTargetPlugin);
|
||||
|
||||
var _LibraryTemplatePlugin = require('webpack/lib/LibraryTemplatePlugin');
|
||||
|
||||
var _LibraryTemplatePlugin2 = _interopRequireDefault(_LibraryTemplatePlugin);
|
||||
|
||||
var _SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin');
|
||||
|
||||
var _SingleEntryPlugin2 = _interopRequireDefault(_SingleEntryPlugin);
|
||||
|
||||
var _LimitChunkCountPlugin = require('webpack/lib/optimize/LimitChunkCountPlugin');
|
||||
|
||||
var _LimitChunkCountPlugin2 = _interopRequireDefault(_LimitChunkCountPlugin);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var NS = _path2.default.dirname(_fs2.default.realpathSync(__filename));
|
||||
|
||||
exports.default = function (source) {
|
||||
return source;
|
||||
};
|
||||
|
||||
function pitch(request) {
|
||||
var _this = this;
|
||||
|
||||
var query = _loaderUtils2.default.getOptions(this) || {};
|
||||
var loaders = this.loaders.slice(this.loaderIndex + 1);
|
||||
this.addDependency(this.resourcePath);
|
||||
// We already in child compiler, return empty bundle
|
||||
if (this[NS] === undefined) {
|
||||
// eslint-disable-line no-undefined
|
||||
throw new Error('"extract-text-webpack-plugin" loader is used without the corresponding plugin, ' + 'refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example');
|
||||
} else if (this[NS] === false) {
|
||||
return '';
|
||||
} else if (this[NS](null, query)) {
|
||||
if (query.omit) {
|
||||
this.loaderIndex += +query.omit + 1;
|
||||
request = request.split('!').slice(+query.omit).join('!');
|
||||
loaders = loaders.slice(+query.omit);
|
||||
}
|
||||
var resultSource = void 0;
|
||||
if (query.remove) {
|
||||
resultSource = '// removed by extract-text-webpack-plugin';
|
||||
} else {
|
||||
resultSource = undefined; // eslint-disable-line no-undefined
|
||||
}
|
||||
|
||||
var childFilename = 'extract-text-webpack-plugin-output-filename'; // eslint-disable-line no-path-concat
|
||||
var publicPath = typeof query.publicPath === 'string' ? query.publicPath : this._compilation.outputOptions.publicPath;
|
||||
var outputOptions = {
|
||||
filename: childFilename,
|
||||
publicPath
|
||||
};
|
||||
var childCompiler = this._compilation.createChildCompiler(`extract-text-webpack-plugin ${NS} ${request}`, outputOptions);
|
||||
childCompiler.apply(new _NodeTemplatePlugin2.default(outputOptions));
|
||||
childCompiler.apply(new _LibraryTemplatePlugin2.default(null, 'commonjs2'));
|
||||
childCompiler.apply(new _NodeTargetPlugin2.default());
|
||||
childCompiler.apply(new _SingleEntryPlugin2.default(this.context, `!!${request}`));
|
||||
childCompiler.apply(new _LimitChunkCountPlugin2.default({ maxChunks: 1 }));
|
||||
// We set loaderContext[NS] = false to indicate we already in
|
||||
// a child compiler so we don't spawn another child compilers from there.
|
||||
childCompiler.plugin('this-compilation', function (compilation) {
|
||||
compilation.plugin('normal-module-loader', function (loaderContext, module) {
|
||||
loaderContext[NS] = false;
|
||||
if (module.request === request) {
|
||||
module.loaders = loaders.map(function (loader) {
|
||||
return {
|
||||
loader: loader.path,
|
||||
options: loader.options
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var source = void 0;
|
||||
childCompiler.plugin('after-compile', function (compilation, callback) {
|
||||
source = compilation.assets[childFilename] && compilation.assets[childFilename].source();
|
||||
|
||||
// Remove all chunk assets
|
||||
compilation.chunks.forEach(function (chunk) {
|
||||
chunk.files.forEach(function (file) {
|
||||
delete compilation.assets[file];
|
||||
});
|
||||
});
|
||||
|
||||
callback();
|
||||
});
|
||||
var callback = this.async();
|
||||
childCompiler.runAsChild(function (err, entries, compilation) {
|
||||
if (err) return callback(err);
|
||||
|
||||
if (compilation.errors.length > 0) {
|
||||
return callback(compilation.errors[0]);
|
||||
}
|
||||
compilation.fileDependencies.forEach(function (dep) {
|
||||
_this.addDependency(dep);
|
||||
}, _this);
|
||||
compilation.contextDependencies.forEach(function (dep) {
|
||||
_this.addContextDependency(dep);
|
||||
}, _this);
|
||||
if (!source) {
|
||||
return callback(new Error("Didn't get a result from child compiler"));
|
||||
}
|
||||
try {
|
||||
var text = _this.exec(source, request);
|
||||
if (typeof text === 'string') {
|
||||
text = [[compilation.entries[0].identifier(), text]];
|
||||
} else {
|
||||
text.forEach(function (item) {
|
||||
var id = item[0];
|
||||
compilation.modules.forEach(function (module) {
|
||||
if (module.id === id) {
|
||||
item[0] = module.identifier();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
_this[NS](text, query);
|
||||
if (text.locals && typeof resultSource !== 'undefined') {
|
||||
resultSource += `\nmodule.exports = ${JSON.stringify(text.locals)};`;
|
||||
}
|
||||
} catch (e) {
|
||||
return callback(e);
|
||||
}
|
||||
if (resultSource) {
|
||||
callback(null, resultSource);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"name": "extract-text-webpack-plugin",
|
||||
"version": "3.0.2",
|
||||
"author": "Tobias Koppers @sokra",
|
||||
"description": "Extract text from bundle into a file.",
|
||||
"license": "MIT",
|
||||
"main": "dist/cjs.js",
|
||||
"files": [
|
||||
"dist",
|
||||
"schema"
|
||||
],
|
||||
"scripts": {
|
||||
"start": "npm run build -- -w",
|
||||
"appveyor:test": "npm run test",
|
||||
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'",
|
||||
"build:example": "(cd example && webpack)",
|
||||
"clean": "del-cli dist",
|
||||
"lint": "eslint --cache src test",
|
||||
"lint-staged": "lint-staged",
|
||||
"prebuild": "npm run clean",
|
||||
"prepublish": "npm run build",
|
||||
"release": "standard-version",
|
||||
"security": "nsp check",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
|
||||
"travis:lint": "npm run lint && npm run security",
|
||||
"travis:test": "npm run test -- --runInBand",
|
||||
"travis:coverage": "npm run test:coverage -- --runInBand",
|
||||
"webpack-defaults": "webpack-defaults"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "^2.4.1",
|
||||
"loader-utils": "^1.1.0",
|
||||
"schema-utils": "^0.3.0",
|
||||
"webpack-sources": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-jest": "^21.2.0",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"cross-env": "^5.1.0",
|
||||
"css-loader": "^0.28.7",
|
||||
"del-cli": "^1.1.0",
|
||||
"eslint": "^4.9.0",
|
||||
"eslint-config-webpack": "^1.2.5",
|
||||
"eslint-plugin-import": "^2.8.0",
|
||||
"file-loader": "^1.1.5",
|
||||
"jest": "^21.2.1",
|
||||
"lint-staged": "^4.3.0",
|
||||
"nsp": "^2.8.1",
|
||||
"pre-commit": "^1.2.2",
|
||||
"raw-loader": "^0.5.1",
|
||||
"standard-version": "^4.2.0",
|
||||
"style-loader": "^0.19.0",
|
||||
"webpack": "^3.8.1",
|
||||
"webpack-defaults": "^1.6.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4.8 < 5.0.0 || >= 5.10"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"webpack": "^3.1.0"
|
||||
},
|
||||
"homepage": "http://github.com/webpack-contrib/extract-text-webpack-plugin",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "http://github.com/webpack-contrib/extract-text-webpack-plugin.git"
|
||||
},
|
||||
"pre-commit": "lint-staged",
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"eslint --fix",
|
||||
"git add"
|
||||
]
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"allChunks": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"disable": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"omit": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"remove": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"fallback": {
|
||||
"type": ["string", "array", "object"]
|
||||
},
|
||||
"filename": {
|
||||
"type": "string"
|
||||
},
|
||||
"use": {
|
||||
"type": ["string", "array", "object"]
|
||||
},
|
||||
"publicPath": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"allChunks": {
|
||||
"description": "",
|
||||
"type": "boolean"
|
||||
},
|
||||
"disable": {
|
||||
"description": "",
|
||||
"type": "boolean"
|
||||
},
|
||||
"fallback": {
|
||||
"description": "A loader that webpack can fall back to if the original one fails.",
|
||||
"modes": {
|
||||
"type": ["string", "object", "array"]
|
||||
}
|
||||
},
|
||||
"filename": {
|
||||
"description": "The filename and path that ExtractTextPlugin will extract to",
|
||||
"modes": {
|
||||
"type": ["string", "function"]
|
||||
}
|
||||
},
|
||||
"ignoreOrder": {
|
||||
"description": "Ignore dependency order (useful for CSS Modules)",
|
||||
"type": "boolean"
|
||||
},
|
||||
"loader": {
|
||||
"description": "The loader that ExtractTextPlugin will attempt to load through.",
|
||||
"modes": {
|
||||
"type": ["string", "object", "array"]
|
||||
}
|
||||
},
|
||||
"publicPath": {
|
||||
"description": "",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user