chore(dep): upgrade html-webpack-plugin to v4 (#7119)

This commit is contained in:
Xin Du (Clark) 2020-05-07 11:52:26 +01:00 committed by GitHub
parent c37c3d4da0
commit 789f0e6555
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 319 additions and 332 deletions

View File

@ -25,7 +25,7 @@
"glob": "^7.1.6",
"hard-source-webpack-plugin": "^0.13.1",
"hash-sum": "^2.0.0",
"html-webpack-plugin": "^3.2.0",
"html-webpack-plugin": "^4.0.0",
"memory-fs": "^0.4.1",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"pify": "^4.0.1",

View File

@ -129,8 +129,7 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
filename: '../server/index.spa.html',
template: appTemplatePath,
minify: buildOptions.html.minify,
inject: true,
chunksSortMode: 'dependency'
inject: true
}),
new VueSSRClientPlugin({
filename: `../server/${this.name}.manifest.json`

View File

@ -1,3 +1,5 @@
import HtmlWebpackPlugin from 'html-webpack-plugin'
export default class CorsPlugin {
constructor ({ crossorigin }) {
this.crossorigin = crossorigin
@ -6,11 +8,11 @@ export default class CorsPlugin {
apply (compiler) {
const ID = 'vue-cors-plugin'
compiler.hooks.compilation.tap(ID, (compilation) => {
compilation.hooks.htmlWebpackPluginAlterAssetTags.tap(ID, (data) => {
HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tap(ID, (data) => {
if (!this.crossorigin) {
return
}
[...data.head, ...data.body].forEach((tag) => {
[...data.headTags, ...data.bodyTags].forEach((tag) => {
if (['script', 'link'].includes(tag.tagName)) {
if (tag.attributes) {
tag.attributes.crossorigin = this.crossorigin

View File

@ -4,6 +4,7 @@
*/
import EventEmitter from 'events'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import { safariNoModuleFix } from '@nuxt/utils'
const assetsMap = {}
@ -42,13 +43,11 @@ export default class ModernModePlugin {
applyLegacy (compiler) {
const ID = 'nuxt-legacy-bundle'
compiler.hooks.compilation.tap(ID, (compilation) => {
// For html-webpack-plugin 4.0
// HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tapAsync(ID, async (data, cb) => {
compilation.hooks.htmlWebpackPluginAlterAssetTags.tapAsync(ID, (data, cb) => {
HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tapAsync(ID, (data, cb) => {
// get stats, write to disk
this.assets = {
name: data.plugin.options.filename,
content: data.body
content: data.bodyTags
}
cb()
@ -59,11 +58,9 @@ export default class ModernModePlugin {
applyModern (compiler) {
const ID = 'nuxt-modern-bundle'
compiler.hooks.compilation.tap(ID, (compilation) => {
// For html-webpack-plugin 4.0
// HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tapAsync(ID, async (data, cb) => {
compilation.hooks.htmlWebpackPluginAlterAssetTags.tapAsync(ID, async (data, cb) => {
HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tapAsync(ID, async (data, cb) => {
// use <script type="module"> for modern assets
data.body.forEach((tag) => {
data.bodyTags.forEach((tag) => {
if (tag.tagName === 'script' && tag.attributes) {
tag.attributes.type = 'module'
}
@ -71,7 +68,7 @@ export default class ModernModePlugin {
// use <link rel="modulepreload"> instead of <link rel="preload">
// for modern assets
data.head.forEach((tag) => {
data.headTags.forEach((tag) => {
if (tag.tagName === 'link' &&
tag.attributes.rel === 'preload' &&
tag.attributes.as === 'script') {
@ -86,7 +83,7 @@ export default class ModernModePlugin {
for (const a of legacyAssets) {
a.attributes.nomodule = true
data.body.push(a)
data.bodyTags.push(a)
}
if (this.noUnsafeInline) {
@ -102,7 +99,7 @@ export default class ModernModePlugin {
source: () => Buffer.from(safariNoModuleFix),
size: () => Buffer.byteLength(safariNoModuleFix)
}
data.body.push({
data.bodyTags.push({
tagName: 'script',
closeTag: true,
attributes: {
@ -111,7 +108,7 @@ export default class ModernModePlugin {
})
} else {
// inject Safari 10 nomodule fix
data.body.push({
data.bodyTags.push({
tagName: 'script',
closeTag: true,
innerHTML: safariNoModuleFix

View File

@ -29,8 +29,8 @@ describe('modern client mode (SPA)', () => {
test('should contain module modern resources', async () => {
const { body: response } = await rp(url('/'))
expect(response).toContain('<script type="module" src="/_nuxt/modern-app.js" crossorigin="use-credentials"')
expect(response).toContain('<script type="module" src="/_nuxt/modern-commons.app.js" crossorigin="use-credentials"')
expect(response).toContain('<script src="/_nuxt/modern-app.js" type="module" crossorigin="use-credentials"')
expect(response).toContain('<script src="/_nuxt/modern-commons.app.js" type="module" crossorigin="use-credentials"')
})
test('should contain legacy preload resources', async () => {

615
yarn.lock

File diff suppressed because it is too large Load Diff