1
1
import { rollup } from 'rollup'
2
- import babel from 'rollup- plugin-babel'
3
- import commonjs from 'rollup- plugin-commonjs '
4
- import nodeResolve from ' rollup- plugin-node-resolve'
5
- import image from ' rollup- plugin-image'
2
+ import babel from '@ rollup/ plugin-babel'
3
+ import nodeResolve from '@ rollup/ plugin-node-resolve '
4
+ const commonjs = require ( '@ rollup/ plugin-commonjs' ) ;
5
+ const image = require ( '@ rollup/ plugin-image') ;
6
6
import { readFileSync } from 'fs'
7
7
import { resolve } from 'path'
8
+ import { Browser } from "puppeteer" ;
9
+ import { createCompiler , assemble } from '../..'
10
+ import { AssembleResults } from "../../src" ;
8
11
9
12
export { compile , build , open , pack }
10
13
11
14
function vue ( ) {
12
15
return {
13
16
name : 'vue' ,
14
- transform ( code , id ) {
17
+ transform ( code : string , id : string ) {
15
18
if ( id . endsWith ( '.vue' ) ) return compile ( id , code )
16
19
}
17
20
}
18
21
}
19
22
20
- function inline ( filename , code ) {
23
+ function inline ( filename : string , code : string | AssembleResults ) {
21
24
return {
22
25
name : 'Inline' ,
23
- resolveId ( id ) {
26
+ resolveId ( id : string ) {
24
27
if ( id === filename ) return filename
25
28
} ,
26
- load ( id ) {
29
+ load ( id : string ) {
27
30
if ( id === filename ) {
28
31
return code
29
32
}
30
33
}
31
34
}
32
35
}
33
36
34
- function load ( ext , handle ) {
37
+ function load ( ext : string , handle : ( T : string ) => string ) {
35
38
return {
36
39
name : 'load' + ext ,
37
- load ( id ) {
38
- if ( id . endsWith ( ext ) ) return handle ( id . split ( ':' ) . pop ( ) )
40
+ load ( id : string ) {
41
+ if ( id . endsWith ( ext ) ) return handle ( id . split ( ':' ) . pop ( ) ! )
39
42
}
40
43
}
41
44
}
42
- import { createCompiler , assemble } from '../..'
45
+
43
46
const compiler = createCompiler ( {
44
47
script : { } ,
45
48
style : { trim : true } ,
@@ -50,7 +53,7 @@ const compiler = createCompiler({
50
53
optimizeSSR : process . env . VUE_ENV === 'server'
51
54
}
52
55
} )
53
- function compile ( filename , source ) {
56
+ function compile ( filename : string , source : string ) {
54
57
const result = compiler . compileToDescriptor ( filename , source )
55
58
56
59
result . styles . forEach ( style => {
@@ -61,13 +64,13 @@ function compile(filename, source) {
61
64
}
62
65
63
66
const babelit = babel ( {
64
- presets : [ [ require . resolve ( 'babel- preset-env' ) , { modules : false } ] ] ,
65
- plugins : [ 'external-helpers' ] ,
67
+ presets : [ [ require . resolve ( '@ babel/ preset-env' ) , { modules : false } ] ] ,
68
+ plugins : [ "@babel/plugin-transform-runtime" ] ,
66
69
babelrc : false ,
67
- runtimeHelpers : true
70
+ babelHelpers : 'runtime' ,
68
71
} )
69
72
70
- async function pack ( filename , source ) {
73
+ async function pack ( filename : string , source : string ) {
71
74
const name = filename + '__temp.js'
72
75
let bundle = await rollup ( < any > {
73
76
input : name ,
@@ -78,23 +81,23 @@ async function pack(filename, source) {
78
81
plugins : [
79
82
load (
80
83
'.png' ,
81
- id =>
84
+ ( id ) =>
82
85
`export default "data:image/png;base64,${ readFileSync (
83
86
id ,
84
87
'base64'
85
88
) } "\n`
86
89
) ,
87
- inline ( name , ( await bundle . generate ( { format : 'cjs' } ) ) . code ) ,
90
+ inline ( name , ( await bundle . generate ( { format : 'cjs' } ) ) . output [ 0 ] . code ) ,
88
91
commonjs ( ) ,
89
92
babelit
90
93
]
91
94
} )
92
95
93
- return ( await bundle . generate ( { format : 'cjs' } ) ) . code
96
+ return ( await bundle . generate ( { format : 'cjs' } ) ) . output [ 0 ] . code
94
97
}
95
98
96
- const cache = { }
97
- async function build ( filename ) {
99
+ const cache : Record < string , string > = { }
100
+ async function build ( filename : string ) {
98
101
if ( filename in cache ) return cache [ filename ]
99
102
const source = compile ( filename , readFileSync ( filename ) . toString ( ) )
100
103
const component = filename + '__.js'
@@ -134,15 +137,15 @@ async function build(filename) {
134
137
vue ( ) ,
135
138
image ( ) ,
136
139
commonjs ( ) ,
137
- inline ( component , generated . code ) ,
140
+ inline ( component , generated . output [ 0 ] . code ) ,
138
141
babelit
139
142
]
140
143
} )
141
144
142
145
cache [ filename ] = ( await bundle . generate ( {
143
146
format : 'iife' ,
144
147
name : 'App'
145
- } ) ) . code
148
+ } ) ) . output [ 0 ] . code
146
149
147
150
return cache [ filename ]
148
151
}
@@ -151,7 +154,7 @@ const vueSource = readFileSync(
151
154
resolve ( __dirname , '../../node_modules/vue/dist/vue.min.js' )
152
155
) . toString ( )
153
156
const escape = ( any : string ) => any . replace ( / < \/ / g, '<\/' )
154
- async function open ( name , browser , code , id = '#test' ) {
157
+ async function open ( name : string , browser : Browser , code : string , id = '#test' ) {
155
158
const page = await browser . newPage ( )
156
159
157
160
const content = `
0 commit comments