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' )
1111
1212/**
1313 * @param {{
@@ -24,96 +24,89 @@ async function build(opts) {
2424 plugins : ( opts . plugins || [ ] ) . concat ( [
2525 buble ( {
2626 transforms : {
27- dangerousForOf : true ,
28- } ,
29- } ) ,
27+ dangerousForOf : true
28+ } } ) ,
3029 commonjs ( ) ,
3130 nodeResolve ( ) ,
3231 replace ( {
3332 __VERSION__ : version ,
34- 'process.env.SSR' : false ,
35- } ) ,
33+ 'process.env.SSR' : false
34+ } )
3635 ] ) ,
3736 onwarn : function ( message ) {
3837 if ( message . code === 'UNRESOLVED_IMPORT' ) {
3938 throw new Error (
4039 `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+ )
4544 }
46- } ,
45+ }
4746 } )
4847 . then ( function ( bundle ) {
49- var dest = 'lib/' + ( opts . output || opts . input ) ;
48+ var dest = 'lib/' + ( opts . output || opts . input )
5049
51- console . log ( dest ) ;
50+ console . log ( dest )
5251 return bundle . write ( {
5352 format : 'iife' ,
54- output : opts . globalName ? { name : opts . globalName } : { } ,
53+ output : opts . globalName ? { name : opts . globalName } : { } ,
5554 file : dest ,
56- strict : false ,
57- } ) ;
58- } ) ;
55+ strict : false
56+ } )
57+ } )
5958}
6059
6160async function buildCore ( ) {
62- const promises = [ ] ;
61+ const promises = [ ]
6362
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+ } ) )
7067
7168 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+ } ) )
7974 }
8075
81- await Promise . all ( promises ) ;
76+ await Promise . all ( promises )
8277}
8378
8479async function buildAllPlugin ( ) {
8580 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+ ]
9691
9792 const promises = plugins . map ( item => {
9893 return build ( {
9994 input : 'src/plugins/' + item . input ,
100- output : 'plugins/' + item . name + '.js' ,
101- } ) ;
102- } ) ;
95+ output : 'plugins/' + item . name + '.js'
96+ } )
97+ } )
10398
10499 if ( isProd ) {
105100 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+ } )
114107 }
115108
116- await Promise . all ( promises ) ;
109+ await Promise . all ( promises )
117110}
118111
119112async function main ( ) {
@@ -123,37 +116,41 @@ async function main() {
123116 atomic : true ,
124117 awaitWriteFinish : {
125118 stabilityThreshold : 1000 ,
126- pollInterval : 100 ,
127- } ,
119+ pollInterval : 100
120+ }
128121 } )
129122 . 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 )
132125 if ( dirs [ 1 ] === 'core' ) {
133- buildCore ( ) ;
126+ buildCore ( )
134127 } else if ( dirs [ 2 ] ) {
135- const name = path . basename ( dirs [ 2 ] , '.js' ) ;
128+ const name = path . basename ( dirs [ 2 ] , '.js' )
136129 const input = `src/plugins/${ name } ${
137130 / \. j s / . test ( dirs [ 2 ] ) ? '' : '/index'
138- } .js`;
131+ } .js`
139132
140133 build ( {
141134 input,
142- output : 'plugins/' + name + '.js' ,
143- } ) ;
135+ output : 'plugins/' + name + '.js'
136+ } )
144137 }
145138 } )
146139 . on ( 'ready' , ( ) => {
147- console . log ( '[start]' ) ;
148- buildCore ( ) ;
149- buildAllPlugin ( ) ;
150- } ) ;
140+ console . log ( '[start]' )
141+ buildCore ( )
142+ buildAllPlugin ( )
143+ } )
151144 } else {
152- await Promise . all ( [ buildCore ( ) , buildAllPlugin ( ) ] ) ;
145+ await Promise . all ( [
146+ buildCore ( ) ,
147+ buildAllPlugin ( )
148+ ] )
153149 }
154150}
155151
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