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