/
rollup.js
88 lines (80 loc) · 2.53 KB
/
rollup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const rollup = require('rollup');
const typescript = require('rollup-plugin-typescript2');
const commonjs = require('@rollup/plugin-commonjs');
const json = require('@rollup/plugin-json');
const resolve = require('@rollup/plugin-node-resolve').nodeResolve;
const terser = require('rollup-plugin-terser').terser;
const banner = require('./banner');
const path = require('path');
const rootPath = path.join(__dirname, '..');
const args = require('minimist')(process.argv.slice(2));
let outDir = args.dist ? './dist' : './tmp';
async function buildBrowser() {
let bundle = await rollup.rollup({
input: './src/less-browser/bootstrap.js',
output: [
{
file: 'less.js',
format: 'umd'
},
{
file: 'less.min.js',
format: 'umd'
}
],
plugins: [
resolve(),
commonjs(),
json(),
typescript({
verbosity: 2,
tsconfigDefaults: {
compilerOptions: {
allowJs: true,
sourceMap: true,
target: 'ES5'
}
},
include: [ '*.ts', '**/*.ts', '*.js', '**/*.js' ],
exclude: ['node_modules'] // only transpile our source code
}),
terser({
compress: true,
include: [/^.+\.min\.js$/],
output: {
comments: function(node, comment) {
if (comment.type == "comment2") {
// preserve banner
return /@license/i.test(comment.value);
}
}
}
})
]
});
if (!args.out || args.out.indexOf('less.js') > -1) {
const file = args.out || `${outDir}/less.js`;
console.log(`Writing ${file}...`);
await bundle.write({
file: path.join(rootPath, file),
format: 'umd',
name: 'less',
banner
});
}
if (!args.out || args.out.indexOf('less.min.js') > -1) {
const file = args.out || `${outDir}/less.min.js`;
console.log(`Writing ${file}...`);
await bundle.write({
file: path.join(rootPath, file),
format: 'umd',
name: 'less',
sourcemap: true,
banner
});
}
}
async function build() {
await buildBrowser();
}
build();