-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathbrowser-javascript.mjs
81 lines (79 loc) · 1.9 KB
/
browser-javascript.mjs
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
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import path from 'node:path';
import terser from '@rollup/plugin-terser';
import { externalsForBrowser } from '../configs/externals.mjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
export function browserJavascript() {
const babelConfig = {
babelHelpers: 'bundled',
presets: [
['@babel/preset-env', {
loose: true,
modules: false,
targets: {
browsers: [
'IE >= 8',
'Opera >= 12',
'Safari >= 5.1',
'Chrome >= 15',
'Edge >= 12',
'Firefox >= 4',
],
},
useBuiltIns: false,
}],
],
};
return [
{
input: 'src/browser.js',
output: [
{ file: 'dist/browser.cjs', format: 'cjs', sourcemap: true, exports: 'auto', strict: false },
{ file: 'dist/browser.mjs', format: 'esm', sourcemap: true, exports: 'auto', strict: false },
],
external: externalsForBrowser,
plugins: [
commonjs({
include: [ 'src/browser.js', 'node_modules/**' ],
}),
nodeResolve({
rootDir: path.join(process.cwd(), '..', '..'),
}),
babel(babelConfig),
terser({
compress: {
reduce_funcs: false, // https://github.com/terser/terser/issues/1305
},
keep_classnames: true,
keep_fnames: true,
ie8: true,
}),
],
},
{
input: 'src/browser-global.js',
output: [
{ file: 'dist/browser-global.js', format: 'iife', sourcemap: true, exports: 'auto', strict: false },
],
external: externalsForBrowser,
plugins: [
commonjs({
include: [ 'src/browser.js', 'node_modules/**' ],
}),
nodeResolve({
rootDir: path.join(process.cwd(), '..', '..'),
}),
babel(babelConfig),
terser({
compress: {
reduce_funcs: false, // https://github.com/terser/terser/issues/1305
},
keep_classnames: true,
keep_fnames: true,
ie8: true,
}),
],
},
];
}