-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathrollup.config.js
86 lines (76 loc) · 2.26 KB
/
rollup.config.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
const path = require('path');
const nodeResolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const babel = require('rollup-plugin-babel');
const terser = require('@rollup/plugin-terser');
const jsxPlugin = require('@babel/plugin-transform-react-jsx');
const cwd = process.cwd();
const pkg = require(path.join(cwd, 'package.json')); // eslint-disable-line
const { name, version } = pkg;
const banner = `/*
* ${name} v${version}
* Copyright (c) ${new Date().getFullYear()} QlikTech International AB
* Released under the MIT license.
*/
`;
const topLevelNodeModulesPath = `..${path.sep}..${path.sep}..${path.sep}node_modules`;
const localNodeModulesPath = `..${path.sep}node_modules`;
const watch = process.argv.indexOf('-w') > 2;
const config = (isEsm) => {
const outputFile = isEsm ? pkg.module : pkg.main;
const basename = path.basename(outputFile);
const dir = path.dirname(outputFile);
const umdName = basename
.replace(/-([a-z])/g, (m, p1) => p1.toUpperCase())
.split('.js')
.join('');
const cfg = {
input: path.resolve(cwd, 'src', 'index'),
output: {
file: path.resolve(dir, basename),
format: isEsm ? 'es' : 'umd',
exports: 'default',
name: umdName,
sourcemap: true,
sourcemapPathTransform: (relativeSourcePath) =>
relativeSourcePath.replace(topLevelNodeModulesPath, localNodeModulesPath),
banner,
},
plugins: [
nodeResolve(),
babel({
include: ['src/**'],
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
browsers: [
'last 2 Chrome versions',
'last 2 Firefox versions',
'last 2 Edge versions',
'Safari >= 11.0',
'iOS >= 12.2',
],
},
},
],
],
plugins: [[jsxPlugin, { pragma: 'h' }]],
}),
commonjs(),
],
};
if (process.env.NODE_ENV === 'production' && !isEsm) {
cfg.plugins.push(
terser({
output: {
preamble: banner,
},
})
);
}
return cfg;
};
module.exports = [watch ? false : config(), config(true)].filter(Boolean);