|
1 | | -import path from 'path' |
2 | | -import Promise from 'bluebird' |
| 1 | +import path from 'path'; |
| 2 | +import Promise from 'bluebird'; |
3 | 3 |
|
4 | 4 | // Copied from html-webpack-plugin |
5 | | -function resolvePublicPath (compilation, filename) { |
| 5 | +function resolvePublicPath(compilation, filename) { |
6 | 6 | let publicPath = typeof compilation.options.output.publicPath !== 'undefined' |
7 | 7 | ? compilation.options.output.publicPath |
8 | | - : path.relative(path.dirname(filename), '.') |
| 8 | + : path.relative(path.dirname(filename), '.'); |
9 | 9 |
|
10 | 10 | if (publicPath.length && publicPath.substr(-1, 1) !== '/') { |
11 | | - publicPath += '/' |
| 11 | + publicPath += '/'; |
12 | 12 | } |
13 | | - return publicPath |
| 13 | + return publicPath; |
14 | 14 | } |
15 | 15 |
|
16 | | -function addFileToAssets (htmlPluginData, compilation, { filename, typeOfAsset = 'js', includeSourcemap = true } = {}) { |
17 | | - if (!filename) return compilation.errors.push(new Error('No filename defined')) |
| 16 | +function addFileToAssets(htmlPluginData, compilation, { filename, typeOfAsset = 'js', includeSourcemap = true } = {}) { |
| 17 | + if (!filename) return compilation.errors.push(new Error('No filename defined')); |
18 | 18 |
|
19 | 19 | return htmlPluginData.plugin.addFileToAssets(filename, compilation) |
20 | | - .then((filename) => htmlPluginData.assets[typeOfAsset].unshift(`${resolvePublicPath(compilation, filename)}${filename}`)) |
| 20 | + .then(addedFilename => htmlPluginData.assets[typeOfAsset].unshift(`${resolvePublicPath(compilation, addedFilename)}${addedFilename}`)) |
21 | 21 | .then(() => { |
22 | 22 | if (includeSourcemap) { |
23 | | - return htmlPluginData.plugin.addFileToAssets(`${filename}.map`, compilation) |
| 23 | + return htmlPluginData.plugin.addFileToAssets(`${filename}.map`, compilation); |
24 | 24 | } |
25 | | - return null |
26 | | - }) |
| 25 | + return null; |
| 26 | + }); |
27 | 27 | } |
28 | 28 |
|
29 | 29 | export default class AddAssetHtmlPlugin { |
30 | | - constructor (assets = []) { |
31 | | - this.assets = Array.isArray(assets) ? assets.slice().reverse() : [assets] |
| 30 | + constructor(assets = []) { |
| 31 | + this.assets = Array.isArray(assets) ? assets.slice().reverse() : [assets]; |
32 | 32 | } |
33 | 33 |
|
34 | | - apply (compiler) { |
35 | | - compiler.plugin('compilation', (compilation) => { |
| 34 | + apply(compiler) { |
| 35 | + compiler.plugin('compilation', compilation => { |
36 | 36 | compilation.plugin('html-webpack-plugin-before-html-generation', (htmlPluginData, callback) => { |
37 | 37 | Promise.mapSeries(this.assets, asset => addFileToAssets(htmlPluginData, compilation, asset)) |
38 | | - .then(() => callback(null, htmlPluginData)) |
39 | | - }) |
40 | | - }) |
| 38 | + .then(() => callback(null, htmlPluginData)); |
| 39 | + }); |
| 40 | + }); |
41 | 41 | } |
42 | 42 | } |
0 commit comments