File tree 3 files changed +21
-4
lines changed
src/server/webpack-plugin
3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 1
1
const hash = require ( 'hash-sum' )
2
2
const uniq = require ( 'lodash.uniq' )
3
- import { isJS } from './util'
3
+ import { isJS , onEmit } from './util'
4
4
5
5
export default class VueSSRClientPlugin {
6
6
constructor ( options = { } ) {
@@ -10,7 +10,7 @@ export default class VueSSRClientPlugin {
10
10
}
11
11
12
12
apply ( compiler ) {
13
- compiler . plugin ( 'emit ', ( compilation , cb ) => {
13
+ onEmit ( compiler , 'vue-client-plugin ', ( compilation , cb ) => {
14
14
const stats = compilation . getStats ( ) . toJson ( )
15
15
16
16
const allFiles = uniq ( stats . assets
Original file line number Diff line number Diff line change 1
- import { validate , isJS } from './util'
1
+ import { validate , isJS , onEmit } from './util'
2
2
3
3
export default class VueSSRServerPlugin {
4
4
constructor ( options = { } ) {
@@ -10,7 +10,7 @@ export default class VueSSRServerPlugin {
10
10
apply ( compiler ) {
11
11
validate ( compiler )
12
12
13
- compiler . plugin ( 'emit ', ( compilation , cb ) => {
13
+ onEmit ( compiler , 'vue-server-plugin ', ( compilation , cb ) => {
14
14
const stats = compilation . getStats ( ) . toJson ( )
15
15
const entryName = Object . keys ( stats . entrypoints ) [ 0 ]
16
16
const entryInfo = stats . entrypoints [ entryName ]
Original file line number Diff line number Diff line change @@ -21,4 +21,21 @@ export const validate = compiler => {
21
21
}
22
22
}
23
23
24
+ export const onEmit = ( compiler , name , hook ) => {
25
+ if ( compiler . hooks ) {
26
+ // Webpack >= 4.0.0
27
+ compiler . hooks . emit . tap ( name ,
28
+ ( compilation ) => new Promise ( ( resolve , reject ) => {
29
+ try {
30
+ hook ( compilation , resolve )
31
+ } catch ( e ) {
32
+ reject ( e )
33
+ }
34
+ } ) )
35
+ } else {
36
+ // Webpack < 4.0.0
37
+ compiler . plugin ( 'emit' , hook )
38
+ }
39
+ }
40
+
24
41
export { isJS , isCSS } from '../util'
You can’t perform that action at this time.
0 commit comments