1
- const rollup = require ( 'rollup' )
2
- const buble = require ( 'rollup-plugin-buble' )
3
- const commonjs = require ( 'rollup-plugin-commonjs' )
4
- const nodeResolve = require ( 'rollup-plugin-node-resolve' )
5
- const { uglify } = require ( 'rollup-plugin-uglify' )
6
- const replace = require ( 'rollup-plugin-replace' )
7
- const isProd = process . env . NODE_ENV === 'production'
8
- const version = process . env . VERSION || require ( '../package.json' ) . version
9
- const chokidar = require ( 'chokidar' )
10
- const path = require ( 'path' )
1
+ const rollup = require ( 'rollup' ) ;
2
+ const buble = require ( 'rollup-plugin-buble' ) ;
3
+ const commonjs = require ( 'rollup-plugin-commonjs' ) ;
4
+ const nodeResolve = require ( 'rollup-plugin-node-resolve' ) ;
5
+ const { terser } = require ( 'rollup-plugin-terser' ) ;
6
+ const replace = require ( 'rollup-plugin-replace' ) ;
7
+ const isProd = process . env . NODE_ENV === 'production' ;
8
+ const version = process . env . VERSION || require ( '../package.json' ) . version ;
9
+ const chokidar = require ( 'chokidar' ) ;
10
+ const path = require ( 'path' ) ;
11
11
12
12
/**
13
13
* @param {{
@@ -24,89 +24,96 @@ async function build(opts) {
24
24
plugins : ( opts . plugins || [ ] ) . concat ( [
25
25
buble ( {
26
26
transforms : {
27
- dangerousForOf : true
28
- } } ) ,
27
+ dangerousForOf : true ,
28
+ } ,
29
+ } ) ,
29
30
commonjs ( ) ,
30
31
nodeResolve ( ) ,
31
32
replace ( {
32
33
__VERSION__ : version ,
33
- 'process.env.SSR' : false
34
- } )
34
+ 'process.env.SSR' : false ,
35
+ } ) ,
35
36
] ) ,
36
37
onwarn : function ( message ) {
37
38
if ( message . code === 'UNRESOLVED_IMPORT' ) {
38
39
throw new Error (
39
40
`Could not resolve module ` +
40
- message . source +
41
- `. Try running 'npm install' or using rollup's 'external' option if this is an external dependency. ` +
42
- `Module ${ message . source } is imported in ${ message . importer } `
43
- )
41
+ message . source +
42
+ `. Try running 'npm install' or using rollup's 'external' option if this is an external dependency. ` +
43
+ `Module ${ message . source } is imported in ${ message . importer } `
44
+ ) ;
44
45
}
45
- }
46
+ } ,
46
47
} )
47
48
. then ( function ( bundle ) {
48
- var dest = 'lib/' + ( opts . output || opts . input )
49
+ var dest = 'lib/' + ( opts . output || opts . input ) ;
49
50
50
- console . log ( dest )
51
+ console . log ( dest ) ;
51
52
return bundle . write ( {
52
53
format : 'iife' ,
53
- output : opts . globalName ? { name : opts . globalName } : { } ,
54
+ output : opts . globalName ? { name : opts . globalName } : { } ,
54
55
file : dest ,
55
- strict : false
56
- } )
57
- } )
56
+ strict : false ,
57
+ } ) ;
58
+ } ) ;
58
59
}
59
60
60
61
async function buildCore ( ) {
61
- const promises = [ ]
62
+ const promises = [ ] ;
62
63
63
- promises . push ( build ( {
64
- input : 'src/core/index.js' ,
65
- output : 'docsify.js' ,
66
- } ) )
64
+ promises . push (
65
+ build ( {
66
+ input : 'src/core/index.js' ,
67
+ output : 'docsify.js' ,
68
+ } )
69
+ ) ;
67
70
68
71
if ( isProd ) {
69
- promises . push ( build ( {
70
- input : 'src/core/index.js' ,
71
- output : 'docsify.min.js' ,
72
- plugins : [ uglify ( ) ]
73
- } ) )
72
+ promises . push (
73
+ build ( {
74
+ input : 'src/core/index.js' ,
75
+ output : 'docsify.min.js' ,
76
+ plugins : [ terser ( ) ] ,
77
+ } )
78
+ ) ;
74
79
}
75
80
76
- await Promise . all ( promises )
81
+ await Promise . all ( promises ) ;
77
82
}
78
83
79
84
async function buildAllPlugin ( ) {
80
85
var plugins = [
81
- { name : 'search' , input : 'search/index.js' } ,
82
- { name : 'ga' , input : 'ga.js' } ,
83
- { name : 'matomo' , input : 'matomo.js' } ,
84
- { name : 'emoji' , input : 'emoji.js' } ,
85
- { name : 'external-script' , input : 'external-script.js' } ,
86
- { name : 'front-matter' , input : 'front-matter/index.js' } ,
87
- { name : 'zoom-image' , input : 'zoom-image.js' } ,
88
- { name : 'disqus' , input : 'disqus.js' } ,
89
- { name : 'gitalk' , input : 'gitalk.js' }
90
- ]
86
+ { name : 'search' , input : 'search/index.js' } ,
87
+ { name : 'ga' , input : 'ga.js' } ,
88
+ { name : 'matomo' , input : 'matomo.js' } ,
89
+ { name : 'emoji' , input : 'emoji.js' } ,
90
+ { name : 'external-script' , input : 'external-script.js' } ,
91
+ { name : 'front-matter' , input : 'front-matter/index.js' } ,
92
+ { name : 'zoom-image' , input : 'zoom-image.js' } ,
93
+ { name : 'disqus' , input : 'disqus.js' } ,
94
+ { name : 'gitalk' , input : 'gitalk.js' } ,
95
+ ] ;
91
96
92
97
const promises = plugins . map ( item => {
93
98
return build ( {
94
99
input : 'src/plugins/' + item . input ,
95
- output : 'plugins/' + item . name + '.js'
96
- } )
97
- } )
100
+ output : 'plugins/' + item . name + '.js' ,
101
+ } ) ;
102
+ } ) ;
98
103
99
104
if ( isProd ) {
100
105
plugins . forEach ( item => {
101
- promises . push ( build ( {
102
- input : 'src/plugins/' + item . input ,
103
- output : 'plugins/' + item . name + '.min.js' ,
104
- plugins : [ uglify ( ) ]
105
- } ) )
106
- } )
106
+ promises . push (
107
+ build ( {
108
+ input : 'src/plugins/' + item . input ,
109
+ output : 'plugins/' + item . name + '.min.js' ,
110
+ plugins : [ terser ( ) ] ,
111
+ } )
112
+ ) ;
113
+ } ) ;
107
114
}
108
115
109
- await Promise . all ( promises )
116
+ await Promise . all ( promises ) ;
110
117
}
111
118
112
119
async function main ( ) {
@@ -116,41 +123,37 @@ async function main() {
116
123
atomic : true ,
117
124
awaitWriteFinish : {
118
125
stabilityThreshold : 1000 ,
119
- pollInterval : 100
120
- }
126
+ pollInterval : 100 ,
127
+ } ,
121
128
} )
122
129
. on ( 'change' , p => {
123
- console . log ( '[watch] ' , p )
124
- const dirs = p . split ( path . sep )
130
+ console . log ( '[watch] ' , p ) ;
131
+ const dirs = p . split ( path . sep ) ;
125
132
if ( dirs [ 1 ] === 'core' ) {
126
- buildCore ( )
133
+ buildCore ( ) ;
127
134
} else if ( dirs [ 2 ] ) {
128
- const name = path . basename ( dirs [ 2 ] , '.js' )
135
+ const name = path . basename ( dirs [ 2 ] , '.js' ) ;
129
136
const input = `src/plugins/${ name } ${
130
137
/ \. j s / . test ( dirs [ 2 ] ) ? '' : '/index'
131
- } .js`
138
+ } .js`;
132
139
133
140
build ( {
134
141
input,
135
- output : 'plugins/' + name + '.js'
136
- } )
142
+ output : 'plugins/' + name + '.js' ,
143
+ } ) ;
137
144
}
138
145
} )
139
146
. on ( 'ready' , ( ) => {
140
- console . log ( '[start]' )
141
- buildCore ( )
142
- buildAllPlugin ( )
143
- } )
147
+ console . log ( '[start]' ) ;
148
+ buildCore ( ) ;
149
+ buildAllPlugin ( ) ;
150
+ } ) ;
144
151
} else {
145
- await Promise . all ( [
146
- buildCore ( ) ,
147
- buildAllPlugin ( )
148
- ] )
152
+ await Promise . all ( [ buildCore ( ) , buildAllPlugin ( ) ] ) ;
149
153
}
150
154
}
151
155
152
- main ( ) . catch ( ( e ) => {
153
- console . error ( e )
154
- process . exit ( 1 )
155
- } )
156
-
156
+ main ( ) . catch ( e => {
157
+ console . error ( e ) ;
158
+ process . exit ( 1 ) ;
159
+ } ) ;
0 commit comments