-
-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathCssModule.js
164 lines (134 loc) · 3.39 KB
/
CssModule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import webpack from 'webpack';
import { MODULE_TYPE } from './utils';
const TYPES = new Set([MODULE_TYPE]);
const CODE_GENERATION_RESULT = {
sources: new Map(),
runtimeRequirements: new Set(),
};
class CssModule extends webpack.Module {
constructor({
context,
identifier,
identifierIndex,
content,
media,
sourceMap,
assets,
assetsInfo,
}) {
super(MODULE_TYPE, context);
this.id = '';
this._context = context;
this._identifier = identifier;
this._identifierIndex = identifierIndex;
this.content = content;
this.media = media;
this.sourceMap = sourceMap;
this.buildInfo = {
assets,
assetsInfo,
};
this.buildMeta = {};
}
// no source() so webpack 4 doesn't do add stuff to the bundle
size() {
return this.content.length;
}
identifier() {
return `css|${this._identifier}|${this._identifierIndex}`;
}
readableIdentifier(requestShortener) {
return `css ${requestShortener.shorten(this._identifier)}${
this._identifierIndex ? ` (${this._identifierIndex})` : ''
}`;
}
// eslint-disable-next-line class-methods-use-this
getSourceTypes() {
return TYPES;
}
// eslint-disable-next-line class-methods-use-this
codeGeneration() {
return CODE_GENERATION_RESULT;
}
nameForCondition() {
const resource = this._identifier.split('!').pop();
const idx = resource.indexOf('?');
if (idx >= 0) {
return resource.substring(0, idx);
}
return resource;
}
updateCacheModule(module) {
this.content = module.content;
this.media = module.media;
this.sourceMap = module.sourceMap;
}
// eslint-disable-next-line class-methods-use-this
needRebuild() {
return true;
}
// eslint-disable-next-line class-methods-use-this
needBuild(context, callback) {
callback(null, false);
}
build(options, compilation, resolver, fileSystem, callback) {
this.buildInfo = {};
this.buildMeta = {};
callback();
}
updateHash(hash, context) {
super.updateHash(hash, context);
hash.update(this.content);
hash.update(this.media || '');
hash.update(this.sourceMap ? JSON.stringify(this.sourceMap) : '');
}
serialize(context) {
const { write } = context;
write(this._context);
write(this._identifier);
write(this._identifierIndex);
write(this.content);
write(this.media);
write(this.sourceMap);
write(this.buildInfo);
super.serialize(context);
}
deserialize(context) {
super.deserialize(context);
}
}
if (webpack.util && webpack.util.serialization) {
webpack.util.serialization.register(
CssModule,
'mini-css-extract-plugin/dist/CssModule',
null,
{
serialize(instance, context) {
instance.serialize(context);
},
deserialize(context) {
const { read } = context;
const contextModule = read();
const identifier = read();
const identifierIndex = read();
const content = read();
const media = read();
const sourceMap = read();
const { assets, assetsInfo } = read();
const dep = new CssModule({
context: contextModule,
identifier,
identifierIndex,
content,
media,
sourceMap,
assets,
assetsInfo,
});
dep.deserialize(context);
return dep;
},
}
);
}
export default CssModule;