|
1 | 1 | const HtmlWebpackPlugin = require('html-webpack-plugin')
|
| 2 | +const { semver } = require('@vue/cli-shared-utils') |
2 | 3 |
|
3 | 4 | const ID = 'vue-cli:pwa-html-plugin'
|
4 | 5 |
|
@@ -183,31 +184,43 @@ module.exports = class HtmlPwaPlugin {
|
183 | 184 | })
|
184 | 185 |
|
185 | 186 | if (!isHrefAbsoluteUrl(this.options.manifestPath)) {
|
186 |
| - compiler.hooks.compilation.tap(ID, compilation => { |
187 |
| - compilation.hooks.processAssets.tap( |
188 |
| - { name: ID, stage: 'PROCESS_ASSETS_STAGE_ADDITIONS' }, |
189 |
| - assets => { |
190 |
| - const { |
191 |
| - name, |
192 |
| - themeColor, |
193 |
| - manifestPath, |
194 |
| - manifestOptions |
195 |
| - } = this.options |
196 |
| - const publicOptions = { |
197 |
| - name, |
198 |
| - short_name: name, |
199 |
| - theme_color: themeColor |
200 |
| - } |
201 |
| - const outputManifest = JSON.stringify( |
202 |
| - Object.assign(publicOptions, defaultManifest, manifestOptions) |
203 |
| - ) |
204 |
| - assets[manifestPath] = { |
205 |
| - source: () => outputManifest, |
206 |
| - size: () => outputManifest.length |
207 |
| - } |
208 |
| - } |
209 |
| - ) |
210 |
| - }) |
| 187 | + const { |
| 188 | + name, |
| 189 | + themeColor, |
| 190 | + manifestPath, |
| 191 | + manifestOptions |
| 192 | + } = this.options |
| 193 | + const publicOptions = { |
| 194 | + name, |
| 195 | + short_name: name, |
| 196 | + theme_color: themeColor |
| 197 | + } |
| 198 | + const outputManifest = JSON.stringify( |
| 199 | + Object.assign(publicOptions, defaultManifest, manifestOptions) |
| 200 | + ) |
| 201 | + const manifestAsset = { |
| 202 | + source: () => outputManifest, |
| 203 | + size: () => outputManifest.length |
| 204 | + } |
| 205 | + |
| 206 | + let webpackMajor = 4 |
| 207 | + if (compiler.webpack) { |
| 208 | + webpackMajor = semver.major(compiler.webpack.version) |
| 209 | + } |
| 210 | + |
| 211 | + if (webpackMajor === 4) { |
| 212 | + compiler.hooks.emit.tapAsync(ID, (data, cb) => { |
| 213 | + data.assets[manifestPath] = manifestAsset |
| 214 | + cb(null, data) |
| 215 | + }) |
| 216 | + } else { |
| 217 | + compiler.hooks.compilation.tap(ID, compilation => { |
| 218 | + compilation.hooks.processAssets.tap( |
| 219 | + { name: ID, stage: 'PROCESS_ASSETS_STAGE_ADDITIONS' }, |
| 220 | + assets => { assets[manifestPath] = manifestAsset } |
| 221 | + ) |
| 222 | + }) |
| 223 | + } |
211 | 224 | }
|
212 | 225 | }
|
213 | 226 | }
|
|
0 commit comments