unplugin-tailwindcss-mangle 0.0.5 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,23 +3,29 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var unplugin$1 = require('unplugin');
6
- var tailwindcssPatch = require('tailwindcss-patch');
6
+ var micromatch = require('micromatch');
7
+ var fs = require('fs');
8
+ var path = require('path');
7
9
  var parse5 = require('parse5');
8
- var _generate = require('@babel/generator');
9
- var parser = require('@babel/parser');
10
- var _traverse = require('@babel/traverse');
10
+ var core = require('@babel/core');
11
11
  var postcss = require('postcss');
12
- var parser$1 = require('postcss-selector-parser');
12
+ var parser = require('postcss-selector-parser');
13
+ var tailwindcssPatch = require('tailwindcss-patch');
13
14
 
14
15
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
15
16
 
16
- var _generate__default = /*#__PURE__*/_interopDefault(_generate);
17
- var _traverse__default = /*#__PURE__*/_interopDefault(_traverse);
17
+ var micromatch__default = /*#__PURE__*/_interopDefault(micromatch);
18
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
19
+ var path__default = /*#__PURE__*/_interopDefault(path);
18
20
  var postcss__default = /*#__PURE__*/_interopDefault(postcss);
19
- var parser__default = /*#__PURE__*/_interopDefault(parser$1);
21
+ var parser__default = /*#__PURE__*/_interopDefault(parser);
20
22
 
21
23
  const pluginName = 'unplugin-tailwindcss-mangle';
22
24
 
25
+ const { isMatch } = micromatch__default["default"];
26
+ const isMangleClass = (className) => {
27
+ return /[-:]/.test(className);
28
+ };
23
29
  function groupBy(arr, cb) {
24
30
  if (!Array.isArray(arr)) {
25
31
  throw new Error('expected an array for first argument');
@@ -49,7 +55,7 @@ function getGroupedEntries(entries, options = {
49
55
  return /\.html?$/.test(file);
50
56
  },
51
57
  jsMatcher(file) {
52
- return /\.js$/.test(file);
58
+ return /\.[cm]?js$/.test(file);
53
59
  }
54
60
  }) {
55
61
  const { cssMatcher, htmlMatcher, jsMatcher } = options;
@@ -67,6 +73,18 @@ function getGroupedEntries(entries, options = {
67
73
  return 'other';
68
74
  }
69
75
  });
76
+ if (!groupedEntries.css) {
77
+ groupedEntries.css = [];
78
+ }
79
+ if (!groupedEntries.html) {
80
+ groupedEntries.html = [];
81
+ }
82
+ if (!groupedEntries.js) {
83
+ groupedEntries.js = [];
84
+ }
85
+ if (!groupedEntries.other) {
86
+ groupedEntries.other = [];
87
+ }
70
88
  return groupedEntries;
71
89
  }
72
90
  const acceptChars = 'abcdefghijklmnopqrstuvwxyz'.split('');
@@ -102,97 +120,36 @@ function escapeStringRegexp(str) {
102
120
  }
103
121
  return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
104
122
  }
105
-
106
- class ClassGenerator {
107
- constructor(opts = {}) {
108
- var _a;
109
- this.newClassMap = {};
110
- this.newClassSize = 0;
111
- this.context = {};
112
- this.opts = opts;
113
- this.classPrefix = (_a = opts.classPrefix) !== null && _a !== void 0 ? _a : 'tw-';
114
- }
115
- defaultClassGenerate() {
116
- const chars = [];
117
- let rest = (this.newClassSize - (this.newClassSize % acceptChars.length)) / acceptChars.length;
118
- if (rest > 0) {
119
- while (true) {
120
- rest -= 1;
121
- const m = rest % acceptChars.length;
122
- const c = acceptChars[m];
123
- chars.push(c);
124
- rest -= m;
125
- if (rest === 0) {
126
- break;
127
- }
128
- rest /= acceptChars.length;
129
- }
130
- }
131
- const prefixIndex = this.newClassSize % acceptChars.length;
132
- const newClassName = `${this.classPrefix}${acceptChars[prefixIndex]}${chars.join('')}`;
133
- return newClassName;
134
- }
135
- ignoreClassName(className) {
136
- return regExpTest(this.opts.ignoreClass, className);
137
- }
138
- includeFilePath(filePath) {
139
- const { include } = this.opts;
140
- if (Array.isArray(include)) {
141
- return regExpTest(include, filePath);
142
- }
143
- else {
144
- return true;
145
- }
146
- }
147
- excludeFilePath(filePath) {
148
- const { exclude } = this.opts;
149
- if (Array.isArray(exclude)) {
150
- return regExpTest(exclude, filePath);
151
- }
152
- else {
153
- return false;
154
- }
123
+ function createGlobMatcher(pattern, fallbackValue = false) {
124
+ if (typeof pattern === 'undefined') {
125
+ return function (file) {
126
+ return fallbackValue;
127
+ };
155
128
  }
156
- isFileIncluded(filePath) {
157
- return this.includeFilePath(filePath) && !this.excludeFilePath(filePath);
129
+ return function (file) {
130
+ return isMatch(file, pattern);
131
+ };
132
+ }
133
+ function getCacheDir(basedir = process.cwd()) {
134
+ return path__default["default"].resolve(basedir, 'node_modules/.cache', pluginName);
135
+ }
136
+ function mkCacheDirectory(cwd = process.cwd()) {
137
+ const cacheDirectory = getCacheDir(cwd);
138
+ const exists = fs__default["default"].existsSync(cacheDirectory);
139
+ if (!exists) {
140
+ fs__default["default"].mkdirSync(cacheDirectory, {
141
+ recursive: true
142
+ });
158
143
  }
159
- transformCssClass(className) {
160
- const key = stripEscapeSequence(className);
161
- const cn = this.newClassMap[key];
162
- if (cn)
163
- return cn.name;
164
- return className;
144
+ return cacheDirectory;
145
+ }
146
+ function cacheDump(filename, data, basedir) {
147
+ try {
148
+ const dir = mkCacheDirectory(basedir);
149
+ fs__default["default"].writeFileSync(path__default["default"].resolve(dir, filename), JSON.stringify(Array.from(data), null, 2), 'utf-8');
165
150
  }
166
- generateClassName(original) {
167
- const opts = this.opts;
168
- original = stripEscapeSequence(original);
169
- const cn = this.newClassMap[original];
170
- if (cn)
171
- return cn;
172
- let newClassName;
173
- if (opts.customGenerate && typeof opts.customGenerate === 'function') {
174
- newClassName = opts.customGenerate(original, opts, this.context);
175
- }
176
- if (!newClassName) {
177
- newClassName = this.defaultClassGenerate();
178
- }
179
- if (opts.reserveClassName && regExpTest(opts.reserveClassName, newClassName)) {
180
- if (opts.log) {
181
- console.log(`The class name has been reserved. ${newClassName}`);
182
- }
183
- this.newClassSize++;
184
- return this.generateClassName(original);
185
- }
186
- if (opts.log) {
187
- console.log(`Minify class name from ${original} to ${newClassName}`);
188
- }
189
- const newClass = {
190
- name: newClassName,
191
- usedBy: []
192
- };
193
- this.newClassMap[original] = newClass;
194
- this.newClassSize++;
195
- return newClass;
151
+ catch (error) {
152
+ console.log(error);
196
153
  }
197
154
  }
198
155
 
@@ -254,12 +211,12 @@ parse5.defaultTreeAdapter.appendChild;
254
211
  * @param {ParentNode=} parent Parent node of the current node
255
212
  * @return {void}
256
213
  */
257
- function traverse$1(node, visitor, parent) {
214
+ function traverse(node, visitor, parent) {
258
215
  const shouldVisitChildren = typeof visitor['pre:node'] !== 'function' ||
259
216
  visitor['pre:node'](node, parent) !== false;
260
217
  if (shouldVisitChildren && isParentNode(node)) {
261
218
  for (const child of node.childNodes) {
262
- traverse$1(child, visitor, node);
219
+ traverse(child, visitor, node);
263
220
  }
264
221
  }
265
222
  if (typeof visitor.node === 'function') {
@@ -292,7 +249,7 @@ function traverse$1(node, visitor, parent) {
292
249
  function htmlHandler(rawSource, options) {
293
250
  const { runtimeSet, classGenerator } = options;
294
251
  const fragment = parse5.parse(rawSource);
295
- traverse$1(fragment, {
252
+ traverse(fragment, {
296
253
  element(node, parent) {
297
254
  const attr = node.attrs.find((x) => x.name === 'class');
298
255
  if (attr) {
@@ -317,11 +274,6 @@ function isValidSelector(selector = '') {
317
274
  }
318
275
  const splitCode = (code) => code.split(/[\s"]+/).filter(isValidSelector);
319
276
 
320
- function getDefaultExportFromNamespaceIfPresent(n) {
321
- return n && Object.prototype.hasOwnProperty.call(n, 'default') ? n.default : n;
322
- }
323
- const generate = getDefaultExportFromNamespaceIfPresent(_generate__default["default"]);
324
- const traverse = getDefaultExportFromNamespaceIfPresent(_traverse__default["default"]);
325
277
  function makeRegex(str) {
326
278
  return new RegExp('(?<=^|[\\s"])' + escapeStringRegexp(str), 'g');
327
279
  }
@@ -345,24 +297,33 @@ function handleValue(str, node, options) {
345
297
  return rawStr;
346
298
  }
347
299
  function jsHandler(rawSource, options) {
348
- const ast = parser.parse(rawSource);
349
- const topt = {
350
- StringLiteral: {
351
- enter(p) {
352
- const n = p.node;
353
- n.value = handleValue(n.value, n, options);
354
- }
355
- },
356
- TemplateElement: {
357
- enter(p) {
358
- const n = p.node;
359
- n.value.raw = handleValue(n.value.raw, n, options);
300
+ const result = core.transformSync(rawSource, {
301
+ babelrc: false,
302
+ ast: true,
303
+ plugins: [
304
+ () => {
305
+ return {
306
+ visitor: {
307
+ StringLiteral: {
308
+ enter(p) {
309
+ const n = p.node;
310
+ n.value = handleValue(n.value, n, options);
311
+ }
312
+ },
313
+ TemplateElement: {
314
+ enter(p) {
315
+ const n = p.node;
316
+ n.value.raw = handleValue(n.value.raw, n, options);
317
+ }
318
+ }
319
+ }
320
+ };
360
321
  }
361
- },
362
- noScope: true
363
- };
364
- traverse(ast, topt);
365
- return generate(ast);
322
+ ],
323
+ sourceMaps: false,
324
+ configFile: false
325
+ });
326
+ return result;
366
327
  }
367
328
 
368
329
  const postcssPlugin = 'postcss-mangle-tailwindcss-plugin';
@@ -377,10 +338,19 @@ const postcssMangleTailwindcssPlugin = (options) => {
377
338
  postcssPlugin,
378
339
  Rule(rule, helper) {
379
340
  rule.selector = parser__default["default"]((selectors) => {
380
- selectors.walk((s) => {
341
+ selectors.walkClasses((s) => {
381
342
  if (s.value) {
382
343
  const hit = newClassMap[s.value];
383
344
  if (hit) {
345
+ if (s.parent) {
346
+ const idx = s.parent.nodes.indexOf(s);
347
+ if (idx > -1) {
348
+ const nextNode = s.parent.nodes[idx + 1];
349
+ if (nextNode && nextNode.type === 'attribute' && nextNode.attribute.indexOf('data-v-') > -1) {
350
+ return;
351
+ }
352
+ }
353
+ }
384
354
  s.value = hit.name;
385
355
  }
386
356
  }
@@ -399,22 +369,155 @@ function cssHandler(rawSource, options) {
399
369
  ]).process(rawSource).css;
400
370
  }
401
371
 
402
- const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
403
- const isMangleClass = (className) => {
404
- return /[-:]/.test(className);
405
- };
372
+ class ClassGenerator {
373
+ newClassMap;
374
+ newClassSize;
375
+ context;
376
+ opts;
377
+ classPrefix;
378
+ constructor(opts = {}) {
379
+ this.newClassMap = {};
380
+ this.newClassSize = 0;
381
+ this.context = {};
382
+ this.opts = opts;
383
+ this.classPrefix = opts.classPrefix ?? 'tw-';
384
+ }
385
+ defaultClassGenerate() {
386
+ const chars = [];
387
+ let rest = (this.newClassSize - (this.newClassSize % acceptChars.length)) / acceptChars.length;
388
+ if (rest > 0) {
389
+ while (true) {
390
+ rest -= 1;
391
+ const m = rest % acceptChars.length;
392
+ const c = acceptChars[m];
393
+ chars.push(c);
394
+ rest -= m;
395
+ if (rest === 0) {
396
+ break;
397
+ }
398
+ rest /= acceptChars.length;
399
+ }
400
+ }
401
+ const prefixIndex = this.newClassSize % acceptChars.length;
402
+ const newClassName = `${this.classPrefix}${acceptChars[prefixIndex]}${chars.join('')}`;
403
+ return newClassName;
404
+ }
405
+ ignoreClassName(className) {
406
+ return regExpTest(this.opts.ignoreClass, className);
407
+ }
408
+ includeFilePath(filePath) {
409
+ const { include } = this.opts;
410
+ if (Array.isArray(include)) {
411
+ return regExpTest(include, filePath);
412
+ }
413
+ else {
414
+ return true;
415
+ }
416
+ }
417
+ excludeFilePath(filePath) {
418
+ const { exclude } = this.opts;
419
+ if (Array.isArray(exclude)) {
420
+ return regExpTest(exclude, filePath);
421
+ }
422
+ else {
423
+ return false;
424
+ }
425
+ }
426
+ isFileIncluded(filePath) {
427
+ return this.includeFilePath(filePath) && !this.excludeFilePath(filePath);
428
+ }
429
+ transformCssClass(className) {
430
+ const key = stripEscapeSequence(className);
431
+ const cn = this.newClassMap[key];
432
+ if (cn)
433
+ return cn.name;
434
+ return className;
435
+ }
436
+ generateClassName(original) {
437
+ const opts = this.opts;
438
+ original = stripEscapeSequence(original);
439
+ const cn = this.newClassMap[original];
440
+ if (cn)
441
+ return cn;
442
+ let newClassName;
443
+ if (opts.customGenerate && typeof opts.customGenerate === 'function') {
444
+ newClassName = opts.customGenerate(original, opts, this.context);
445
+ }
446
+ if (!newClassName) {
447
+ newClassName = this.defaultClassGenerate();
448
+ }
449
+ if (opts.reserveClassName && regExpTest(opts.reserveClassName, newClassName)) {
450
+ if (opts.log) {
451
+ console.log(`The class name has been reserved. ${newClassName}`);
452
+ }
453
+ this.newClassSize++;
454
+ return this.generateClassName(original);
455
+ }
456
+ if (opts.log) {
457
+ console.log(`Minify class name from ${original} to ${newClassName}`);
458
+ }
459
+ const newClass = {
460
+ name: newClassName,
461
+ usedBy: []
462
+ };
463
+ this.newClassMap[original] = newClass;
464
+ this.newClassSize++;
465
+ return newClass;
466
+ }
467
+ }
468
+
469
+ function getOptions(options = {}) {
470
+ const includeMatcher = createGlobMatcher(options.include, true);
471
+ const excludeMatcher = createGlobMatcher(options.exclude, false);
472
+ function isInclude(file) {
473
+ return includeMatcher(file) && !excludeMatcher(file);
474
+ }
406
475
  let classSet;
476
+ const classSetOutputOptions = {
477
+ filename: 'classSet.json',
478
+ type: 'partial'
479
+ };
480
+ const classMapOutputOptions = {
481
+ filename: 'classMap.json'
482
+ };
483
+ if (typeof options.classSetOutput === 'object') {
484
+ Object.assign(classSetOutputOptions, options.classSetOutput);
485
+ }
486
+ if (typeof options.classMapOutput === 'object') {
487
+ Object.assign(classMapOutputOptions, options.classMapOutput);
488
+ }
407
489
  const classGenerator = new ClassGenerator(options.classGenerator);
408
490
  function getCachedClassSet() {
409
491
  const set = tailwindcssPatch.getClassCacheSet();
492
+ const isOutput = set.size && options.classSetOutput;
493
+ if (isOutput && classSetOutputOptions.type === 'all') {
494
+ cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
495
+ }
410
496
  set.forEach((c) => {
411
497
  if (!isMangleClass(c)) {
412
498
  set.delete(c);
413
499
  }
414
500
  });
501
+ if (isOutput && classSetOutputOptions.type === 'partial') {
502
+ cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
503
+ }
415
504
  classSet = set;
416
505
  return classSet;
417
506
  }
507
+ return {
508
+ getCachedClassSet,
509
+ classGenerator,
510
+ includeMatcher,
511
+ excludeMatcher,
512
+ isInclude,
513
+ classSetOutputOptions,
514
+ classMapOutputOptions
515
+ };
516
+ }
517
+
518
+ const outputCachedMap = new Map();
519
+ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
520
+ const { classGenerator, getCachedClassSet, isInclude, classMapOutputOptions } = getOptions(options);
418
521
  return {
419
522
  name: pluginName,
420
523
  enforce: 'post',
@@ -428,29 +531,38 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
428
531
  const groupedEntries = getGroupedEntries(Object.entries(bundle));
429
532
  if (Array.isArray(groupedEntries.html) && groupedEntries.html.length) {
430
533
  for (let i = 0; i < groupedEntries.html.length; i++) {
431
- const [, asset] = groupedEntries.html[i];
432
- asset.source = htmlHandler(asset.source.toString(), {
433
- classGenerator,
434
- runtimeSet
435
- });
534
+ const [file, asset] = groupedEntries.html[i];
535
+ if (isInclude(file)) {
536
+ asset.source = htmlHandler(asset.source.toString(), {
537
+ classGenerator,
538
+ runtimeSet
539
+ });
540
+ }
436
541
  }
437
542
  }
438
543
  if (Array.isArray(groupedEntries.js) && groupedEntries.js.length) {
439
544
  for (let i = 0; i < groupedEntries.js.length; i++) {
440
- const [, chunk] = groupedEntries.js[i];
441
- chunk.code = jsHandler(chunk.code, {
442
- runtimeSet,
443
- classGenerator
444
- }).code;
545
+ const [file, chunk] = groupedEntries.js[i];
546
+ if (isInclude(file)) {
547
+ const code = jsHandler(chunk.code, {
548
+ runtimeSet,
549
+ classGenerator
550
+ }).code;
551
+ if (code) {
552
+ chunk.code = code;
553
+ }
554
+ }
445
555
  }
446
556
  }
447
557
  if (Array.isArray(groupedEntries.css) && groupedEntries.css.length) {
448
558
  for (let i = 0; i < groupedEntries.css.length; i++) {
449
- const [, css] = groupedEntries.css[i];
450
- css.source = cssHandler(css.source.toString(), {
451
- classGenerator,
452
- runtimeSet
453
- });
559
+ const [file, css] = groupedEntries.css[i];
560
+ if (isInclude(file)) {
561
+ css.source = cssHandler(css.source.toString(), {
562
+ classGenerator,
563
+ runtimeSet
564
+ });
565
+ }
454
566
  }
455
567
  }
456
568
  }
@@ -459,51 +571,143 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
459
571
  webpack(compiler) {
460
572
  const Compilation = compiler.webpack.Compilation;
461
573
  const { ConcatSource } = compiler.webpack.sources;
574
+ function getAssetPath(outputPath, file, abs = true) {
575
+ const fn = abs ? path__default["default"].resolve : path__default["default"].relative;
576
+ return fn(compiler.context, path__default["default"].resolve(outputPath, file));
577
+ }
578
+ function overwriteServerSideAsset(outputPath, file, data) {
579
+ const abs = getAssetPath(outputPath, file);
580
+ const rel = getAssetPath(outputPath, file, false);
581
+ try {
582
+ fs__default["default"].writeFileSync(abs, data, 'utf-8');
583
+ console.log('[tailwindcss-mangle]: ' + rel + ' overwrited successfully');
584
+ }
585
+ catch (error) {
586
+ console.log('[tailwindcss-mangle]: ' + rel + ' overwrited fail!');
587
+ console.log(error);
588
+ }
589
+ }
462
590
  compiler.hooks.compilation.tap(pluginName, (compilation) => {
463
591
  compilation.hooks.processAssets.tap({
464
592
  name: pluginName,
465
593
  stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
466
594
  }, (assets) => {
467
595
  const runtimeSet = getCachedClassSet();
596
+ const groupedEntries = getGroupedEntries(Object.entries(assets));
468
597
  if (!runtimeSet.size) {
598
+ const css = new Map();
599
+ const html = new Map();
600
+ const js = new Map();
601
+ groupedEntries.css.forEach(([file, source]) => {
602
+ css.set(file, source);
603
+ });
604
+ groupedEntries.html.forEach(([file, source]) => {
605
+ html.set(file, source);
606
+ });
607
+ groupedEntries.js.forEach(([file, source]) => {
608
+ js.set(file, source);
609
+ });
610
+ if (js.size || css.size || html.size) {
611
+ outputCachedMap.set(compiler.outputPath, {
612
+ css,
613
+ html,
614
+ js
615
+ });
616
+ }
469
617
  return;
470
618
  }
471
- const groupedEntries = getGroupedEntries(Object.entries(assets));
472
- if (Array.isArray(groupedEntries.html) && groupedEntries.html.length) {
619
+ if (groupedEntries.html.length) {
473
620
  for (let i = 0; i < groupedEntries.html.length; i++) {
474
621
  const [file, asset] = groupedEntries.html[i];
475
- const html = htmlHandler(asset.source().toString(), {
476
- classGenerator,
477
- runtimeSet
478
- });
479
- const source = new ConcatSource(html);
480
- compilation.updateAsset(file, source);
622
+ if (isInclude(file)) {
623
+ const html = htmlHandler(asset.source().toString(), {
624
+ classGenerator,
625
+ runtimeSet
626
+ });
627
+ const source = new ConcatSource(html);
628
+ compilation.updateAsset(file, source);
629
+ }
481
630
  }
482
631
  }
483
- if (Array.isArray(groupedEntries.js) && groupedEntries.js.length) {
632
+ if (groupedEntries.js.length) {
484
633
  for (let i = 0; i < groupedEntries.js.length; i++) {
485
634
  const [file, chunk] = groupedEntries.js[i];
486
- const code = jsHandler(chunk.source().toString(), {
487
- runtimeSet,
488
- classGenerator
489
- }).code;
490
- const source = new ConcatSource(code);
491
- compilation.updateAsset(file, source);
635
+ if (isInclude(file)) {
636
+ const code = jsHandler(chunk.source().toString(), {
637
+ runtimeSet,
638
+ classGenerator
639
+ }).code;
640
+ if (code) {
641
+ const source = new ConcatSource(code);
642
+ compilation.updateAsset(file, source);
643
+ }
644
+ }
492
645
  }
493
646
  }
494
- if (Array.isArray(groupedEntries.css) && groupedEntries.css.length) {
647
+ if (groupedEntries.css.length) {
495
648
  for (let i = 0; i < groupedEntries.css.length; i++) {
496
649
  const [file, css] = groupedEntries.css[i];
497
- const newCss = cssHandler(css.source().toString(), {
498
- classGenerator,
499
- runtimeSet
500
- });
501
- const source = new ConcatSource(newCss);
502
- compilation.updateAsset(file, source);
650
+ if (isInclude(file)) {
651
+ const newCss = cssHandler(css.source().toString(), {
652
+ classGenerator,
653
+ runtimeSet
654
+ });
655
+ const source = new ConcatSource(newCss);
656
+ compilation.updateAsset(file, source);
657
+ }
503
658
  }
504
659
  }
660
+ outputCachedMap.forEach(({ js, html, css }, key) => {
661
+ if (html.size) {
662
+ html.forEach((asset, file) => {
663
+ if (isInclude(file)) {
664
+ const html = htmlHandler(asset.source().toString(), {
665
+ classGenerator,
666
+ runtimeSet
667
+ });
668
+ overwriteServerSideAsset(key, file, html);
669
+ }
670
+ });
671
+ html.clear();
672
+ }
673
+ if (js.size) {
674
+ js.forEach((chunk, file) => {
675
+ if (isInclude(file)) {
676
+ const rawCode = chunk.source().toString();
677
+ const code = jsHandler(rawCode, {
678
+ runtimeSet,
679
+ classGenerator
680
+ }).code;
681
+ if (code) {
682
+ overwriteServerSideAsset(key, file, code);
683
+ }
684
+ }
685
+ });
686
+ js.clear();
687
+ }
688
+ if (css.size) {
689
+ css.forEach((style, file) => {
690
+ if (isInclude(file)) {
691
+ const newCss = cssHandler(style.source().toString(), {
692
+ classGenerator,
693
+ runtimeSet
694
+ });
695
+ overwriteServerSideAsset(key, file, newCss);
696
+ }
697
+ });
698
+ css.clear();
699
+ }
700
+ });
505
701
  });
506
702
  });
703
+ },
704
+ writeBundle() {
705
+ const entries = Object.entries(classGenerator.newClassMap);
706
+ if (entries.length && classMapOutputOptions) {
707
+ cacheDump(classMapOutputOptions.filename, entries.map((x) => {
708
+ return [x[0], x[1].name];
709
+ }), classMapOutputOptions.dir);
710
+ }
507
711
  }
508
712
  };
509
713
  });