Skip to content

Commit 27d4952

Browse files
committed
Revert "Revert "Replace rollup’s uglify plugin with terser""
This reverts commit e06fed4.
1 parent 16aec44 commit 27d4952

File tree

3 files changed

+218
-112
lines changed

3 files changed

+218
-112
lines changed

Diff for: build/build.js

+81-78
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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');
1111

1212
/**
1313
* @param {{
@@ -24,89 +24,96 @@ async function build(opts) {
2424
plugins: (opts.plugins || []).concat([
2525
buble({
2626
transforms: {
27-
dangerousForOf: true
28-
}}),
27+
dangerousForOf: true,
28+
},
29+
}),
2930
commonjs(),
3031
nodeResolve(),
3132
replace({
3233
__VERSION__: version,
33-
'process.env.SSR': false
34-
})
34+
'process.env.SSR': false,
35+
}),
3536
]),
3637
onwarn: function (message) {
3738
if (message.code === 'UNRESOLVED_IMPORT') {
3839
throw new Error(
3940
`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+
);
4445
}
45-
}
46+
},
4647
})
4748
.then(function (bundle) {
48-
var dest = 'lib/' + (opts.output || opts.input)
49+
var dest = 'lib/' + (opts.output || opts.input);
4950

50-
console.log(dest)
51+
console.log(dest);
5152
return bundle.write({
5253
format: 'iife',
53-
output: opts.globalName ? {name: opts.globalName} : {},
54+
output: opts.globalName ? { name: opts.globalName } : {},
5455
file: dest,
55-
strict: false
56-
})
57-
})
56+
strict: false,
57+
});
58+
});
5859
}
5960

6061
async function buildCore() {
61-
const promises = []
62+
const promises = [];
6263

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+
);
6770

6871
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+
);
7479
}
7580

76-
await Promise.all(promises)
81+
await Promise.all(promises);
7782
}
7883

7984
async function buildAllPlugin() {
8085
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+
];
9196

9297
const promises = plugins.map(item => {
9398
return build({
9499
input: 'src/plugins/' + item.input,
95-
output: 'plugins/' + item.name + '.js'
96-
})
97-
})
100+
output: 'plugins/' + item.name + '.js',
101+
});
102+
});
98103

99104
if (isProd) {
100105
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+
});
107114
}
108115

109-
await Promise.all(promises)
116+
await Promise.all(promises);
110117
}
111118

112119
async function main() {
@@ -116,41 +123,37 @@ async function main() {
116123
atomic: true,
117124
awaitWriteFinish: {
118125
stabilityThreshold: 1000,
119-
pollInterval: 100
120-
}
126+
pollInterval: 100,
127+
},
121128
})
122129
.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);
125132
if (dirs[1] === 'core') {
126-
buildCore()
133+
buildCore();
127134
} else if (dirs[2]) {
128-
const name = path.basename(dirs[2], '.js')
135+
const name = path.basename(dirs[2], '.js');
129136
const input = `src/plugins/${name}${
130137
/\.js/.test(dirs[2]) ? '' : '/index'
131-
}.js`
138+
}.js`;
132139

133140
build({
134141
input,
135-
output: 'plugins/' + name + '.js'
136-
})
142+
output: 'plugins/' + name + '.js',
143+
});
137144
}
138145
})
139146
.on('ready', () => {
140-
console.log('[start]')
141-
buildCore()
142-
buildAllPlugin()
143-
})
147+
console.log('[start]');
148+
buildCore();
149+
buildAllPlugin();
150+
});
144151
} else {
145-
await Promise.all([
146-
buildCore(),
147-
buildAllPlugin()
148-
])
152+
await Promise.all([buildCore(), buildAllPlugin()]);
149153
}
150154
}
151155

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

Comments
 (0)