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 { 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,90 +24,97 @@ 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: [uglify()]
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 : 'gtag' , input : 'gtag.js' } ,
84
- { name : 'matomo' , input : 'matomo.js' } ,
85
- { name : 'emoji' , input : 'emoji.js' } ,
86
- { name : 'external-script' , input : 'external-script.js' } ,
87
- { name : 'front-matter' , input : 'front-matter/index.js' } ,
88
- { name : 'zoom-image' , input : 'zoom-image.js' } ,
89
- { name : 'disqus' , input : 'disqus.js' } ,
90
- { name : 'gitalk' , input : 'gitalk.js' }
91
- ]
86
+ { name : 'search' , input : 'search/index.js' } ,
87
+ { name : 'ga' , input : 'ga.js' } ,
88
+ { name : 'gtag' , input : 'gtag.js' } ,
89
+ { name : 'matomo' , input : 'matomo.js' } ,
90
+ { name : 'emoji' , input : 'emoji.js' } ,
91
+ { name : 'external-script' , input : 'external-script.js' } ,
92
+ { name : 'front-matter' , input : 'front-matter/index.js' } ,
93
+ { name : 'zoom-image' , input : 'zoom-image.js' } ,
94
+ { name : 'disqus' , input : 'disqus.js' } ,
95
+ { name : 'gitalk' , input : 'gitalk.js' } ,
96
+ ] ;
92
97
93
98
const promises = plugins . map ( item => {
94
99
return build ( {
95
100
input : 'src/plugins/' + item . input ,
96
- output : 'plugins/' + item . name + '.js'
97
- } )
98
- } )
101
+ output : 'plugins/' + item . name + '.js' ,
102
+ } ) ;
103
+ } ) ;
99
104
100
105
if ( isProd ) {
101
106
plugins . forEach ( item => {
102
- promises . push ( build ( {
103
- input : 'src/plugins/' + item . input ,
104
- output : 'plugins/' + item . name + '.min.js' ,
105
- plugins : [ uglify ( ) ]
106
- } ) )
107
- } )
107
+ promises . push (
108
+ build ( {
109
+ input : 'src/plugins/' + item . input ,
110
+ output : 'plugins/' + item . name + '.min.js' ,
111
+ // plugins: [uglify()]
112
+ } )
113
+ ) ;
114
+ } ) ;
108
115
}
109
116
110
- await Promise . all ( promises )
117
+ await Promise . all ( promises ) ;
111
118
}
112
119
113
120
async function main ( ) {
@@ -117,41 +124,37 @@ async function main() {
117
124
atomic : true ,
118
125
awaitWriteFinish : {
119
126
stabilityThreshold : 1000 ,
120
- pollInterval : 100
121
- }
127
+ pollInterval : 100 ,
128
+ } ,
122
129
} )
123
130
. on ( 'change' , p => {
124
- console . log ( '[watch] ' , p )
125
- const dirs = p . split ( path . sep )
131
+ console . log ( '[watch] ' , p ) ;
132
+ const dirs = p . split ( path . sep ) ;
126
133
if ( dirs [ 1 ] === 'core' ) {
127
- buildCore ( )
134
+ buildCore ( ) ;
128
135
} else if ( dirs [ 2 ] ) {
129
- const name = path . basename ( dirs [ 2 ] , '.js' )
136
+ const name = path . basename ( dirs [ 2 ] , '.js' ) ;
130
137
const input = `src/plugins/${ name } ${
131
138
/ \. j s / . test ( dirs [ 2 ] ) ? '' : '/index'
132
- } .js`
139
+ } .js`;
133
140
134
141
build ( {
135
142
input,
136
- output : 'plugins/' + name + '.js'
137
- } )
143
+ output : 'plugins/' + name + '.js' ,
144
+ } ) ;
138
145
}
139
146
} )
140
147
. on ( 'ready' , ( ) => {
141
- console . log ( '[start]' )
142
- buildCore ( )
143
- buildAllPlugin ( )
144
- } )
148
+ console . log ( '[start]' ) ;
149
+ buildCore ( ) ;
150
+ buildAllPlugin ( ) ;
151
+ } ) ;
145
152
} else {
146
- await Promise . all ( [
147
- buildCore ( ) ,
148
- buildAllPlugin ( )
149
- ] )
153
+ await Promise . all ( [ buildCore ( ) , buildAllPlugin ( ) ] ) ;
150
154
}
151
155
}
152
156
153
- main ( ) . catch ( ( e ) => {
154
- console . error ( e )
155
- process . exit ( 1 )
156
- } )
157
-
157
+ main ( ) . catch ( e => {
158
+ console . error ( e ) ;
159
+ process . exit ( 1 ) ;
160
+ } ) ;
0 commit comments