1
1
/* eslint-disable */
2
- var fs = require ( 'fs' ) ;
3
- var ConcatSource = require ( "webpack-sources" ) . ConcatSource ;
4
- var async = require ( "async" ) ;
5
- var ExtractedModule = require ( "./ExtractedModule" ) ;
6
- var Chunk = require ( "webpack/lib/Chunk" ) ;
7
- var OrderUndefinedError = require ( "./OrderUndefinedError" ) ;
8
- var loaderUtils = require ( "loader-utils" ) ;
9
- var validateOptions = require ( 'schema-utils' ) ;
10
- var path = require ( 'path' ) ;
2
+ import fs from 'fs' ;
3
+ import path from 'path' ;
4
+ import Chunk from 'webpack/lib/Chunk' ;
5
+ import { ConcatSource } from 'webpack-sources' ;
6
+ import async from 'async' ;
7
+ import loaderUtils from 'loader-utils' ;
8
+ import validateOptions from 'schema-utils' ;
9
+ import ExtractTextPluginCompilation from './lib/ExtractTextPluginCompilation' ;
10
+ import OrderUndefinedError from './lib/OrderUndefinedError' ;
11
+ import {
12
+ isInitialOrHasNoParents ,
13
+ isInvalidOrder ,
14
+ getOrder ,
15
+ getLoaderObject ,
16
+ mergeOptions ,
17
+ isString ,
18
+ isFunction ,
19
+ } from './lib/helpers' ;
11
20
12
21
var NS = fs . realpathSync ( __dirname ) ;
13
22
14
23
var nextId = 0 ;
15
24
16
- function ExtractTextPluginCompilation ( ) {
17
- this . modulesByIdentifier = { } ;
18
- }
19
-
20
- function isInitialOrHasNoParents ( chunk ) {
21
- return chunk . isInitial ( ) || chunk . parents . length === 0 ;
22
- }
23
-
24
25
ExtractTextPlugin . prototype . mergeNonInitialChunks = function ( chunk , intoChunk , checkedChunks ) {
25
26
if ( ! intoChunk ) {
26
27
checkedChunks = [ ] ;
@@ -41,36 +42,6 @@ ExtractTextPlugin.prototype.mergeNonInitialChunks = function(chunk, intoChunk, c
41
42
}
42
43
} ;
43
44
44
- ExtractTextPluginCompilation . prototype . addModule = function ( identifier , originalModule , source , additionalInformation , sourceMap , prevModules ) {
45
- var m ;
46
- if ( ! this . modulesByIdentifier [ identifier ] ) {
47
- m = this . modulesByIdentifier [ identifier ] = new ExtractedModule ( identifier , originalModule , source , sourceMap , additionalInformation , prevModules ) ;
48
- } else {
49
- m = this . modulesByIdentifier [ identifier ] ;
50
- m . addPrevModules ( prevModules ) ;
51
- if ( originalModule . index2 < m . getOriginalModule ( ) . index2 ) {
52
- m . setOriginalModule ( originalModule ) ;
53
- }
54
- }
55
- return m ;
56
- } ;
57
-
58
- ExtractTextPluginCompilation . prototype . addResultToChunk = function ( identifier , result , originalModule , extractedChunk ) {
59
- if ( ! Array . isArray ( result ) ) {
60
- result = [ [ identifier , result ] ] ;
61
- }
62
- var counterMap = { } ;
63
- var prevModules = [ ] ;
64
- result . forEach ( function ( item ) {
65
- var c = counterMap [ item [ 0 ] ] ;
66
- var module = this . addModule . call ( this , item [ 0 ] + ( c || "" ) , originalModule , item [ 1 ] , item [ 2 ] , item [ 3 ] , prevModules . slice ( ) ) ;
67
- extractedChunk . addModule ( module ) ;
68
- module . addChunk ( extractedChunk ) ;
69
- counterMap [ item [ 0 ] ] = ( c || 0 ) + 1 ;
70
- prevModules . push ( module ) ;
71
- } , this ) ;
72
- } ;
73
-
74
45
ExtractTextPlugin . prototype . renderExtractedChunk = function ( chunk ) {
75
46
var source = new ConcatSource ( ) ;
76
47
chunk . modules . forEach ( function ( module ) {
@@ -80,32 +51,6 @@ ExtractTextPlugin.prototype.renderExtractedChunk = function(chunk) {
80
51
return source ;
81
52
} ;
82
53
83
- function isInvalidOrder ( a , b ) {
84
- var bBeforeA = a . getPrevModules ( ) . indexOf ( b ) >= 0 ;
85
- var aBeforeB = b . getPrevModules ( ) . indexOf ( a ) >= 0 ;
86
- return aBeforeB && bBeforeA ;
87
- }
88
-
89
- function getOrder ( a , b ) {
90
- var aOrder = a . getOrder ( ) ;
91
- var bOrder = b . getOrder ( ) ;
92
- if ( aOrder < bOrder ) return - 1 ;
93
- if ( aOrder > bOrder ) return 1 ;
94
- var aIndex = a . getOriginalModule ( ) . index2 ;
95
- var bIndex = b . getOriginalModule ( ) . index2 ;
96
- if ( aIndex < bIndex ) return - 1 ;
97
- if ( aIndex > bIndex ) return 1 ;
98
- var bBeforeA = a . getPrevModules ( ) . indexOf ( b ) >= 0 ;
99
- var aBeforeB = b . getPrevModules ( ) . indexOf ( a ) >= 0 ;
100
- if ( aBeforeB && ! bBeforeA ) return - 1 ;
101
- if ( ! aBeforeB && bBeforeA ) return 1 ;
102
- var ai = a . identifier ( ) ;
103
- var bi = b . identifier ( ) ;
104
- if ( ai < bi ) return - 1 ;
105
- if ( ai > bi ) return 1 ;
106
- return 0 ;
107
- }
108
-
109
54
function ExtractTextPlugin ( options ) {
110
55
if ( arguments . length > 1 ) {
111
56
throw new Error ( "Breaking change: ExtractTextPlugin now only takes a single argument. Either an options " +
@@ -134,33 +79,6 @@ function ExtractTextPlugin(options) {
134
79
}
135
80
module . exports = ExtractTextPlugin ;
136
81
137
- function getLoaderObject ( loader ) {
138
- if ( isString ( loader ) ) {
139
- return { loader : loader } ;
140
- }
141
- return loader ;
142
- }
143
-
144
- function mergeOptions ( a , b ) {
145
- if ( ! b ) return a ;
146
- Object . keys ( b ) . forEach ( function ( key ) {
147
- a [ key ] = b [ key ] ;
148
- } ) ;
149
- return a ;
150
- }
151
-
152
- function isString ( a ) {
153
- return typeof a === "string" ;
154
- }
155
-
156
- function isFunction ( a ) {
157
- return isType ( 'Function' , a ) ;
158
- }
159
-
160
- function isType ( type , obj ) {
161
- return Object . prototype . toString . call ( obj ) === '[object ' + type + ']' ;
162
- }
163
-
164
82
ExtractTextPlugin . loader = function ( options ) {
165
83
return { loader : require . resolve ( "./loader" ) , options : options } ;
166
84
} ;
0 commit comments