|
1 | 1 | const path = require('path') |
2 | 2 | const fs = require('fs') |
| 3 | +const cleaner = require('clean-html') |
3 | 4 | const utils = require('./utils') |
4 | 5 |
|
| 6 | +const htmlCleanerOpts = { |
| 7 | + 'add-break-around-tags': ['li', 'ul'] |
| 8 | +} |
| 9 | + |
5 | 10 | class FileIncludeWebpackPlugin { |
6 | 11 | constructor(config) { |
7 | | - this.source = config.source // source from the context |
| 12 | + // source from the context |
| 13 | + this.source = config.source |
8 | 14 | this.replace = config.replace |
9 | 15 | this.destination = config.destination |
10 | 16 | this.context = null |
| 17 | + this.cleanerOptions = { |
| 18 | + ...htmlCleanerOpts, |
| 19 | + ...(config.cleanerOptions || {}), |
| 20 | + } |
11 | 21 |
|
12 | 22 | // handlers |
13 | 23 | this.process = this.process.bind(this) |
@@ -53,16 +63,18 @@ class FileIncludeWebpackPlugin { |
53 | 63 |
|
54 | 64 | utils.logger.info(`Working on ${files.length} .html files`) |
55 | 65 |
|
56 | | - files.forEach(file => { |
| 66 | + for (const file of files) { |
57 | 67 | const sourcePath = path.join(this.context, file) |
58 | 68 | const destinationPath = this.destination ? path.join(this.destination, file) : file |
59 | 69 | const content = this.processFile(compilation, this.context, sourcePath) |
60 | 70 |
|
61 | | - compilation.assets[destinationPath] = { |
62 | | - source: () => content, |
63 | | - size: () => content.length |
64 | | - } |
65 | | - }) |
| 71 | + cleaner.clean(content, this.cleanerOptions, cleanHtml => { |
| 72 | + compilation.assets[destinationPath] = { |
| 73 | + source: () => cleanHtml, |
| 74 | + size: () => cleanHtml.length |
| 75 | + } |
| 76 | + }) |
| 77 | + } |
66 | 78 |
|
67 | 79 | callback() |
68 | 80 | } |
|
0 commit comments