-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
62 lines (51 loc) · 1.91 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
import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
var fs = require('fs');
var path = require('path');
var srcPath = (path.resolve('./src')).replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
var srcPathRegex = new RegExp(srcPath)
// Disable module transform when building for rollup
var babelRC = JSON.parse(fs.readFileSync('./.babelrc', { encoding: 'UTF-8'}))
babelRC.babelrc = false;
babelRC.presets[0][1].env.modules = false
// Add babel-external-helpers plugin, which helps rollup dedupe injected code
babelRC.presets[0][1].additionalPlugins = babelRC.presets[0][1].additionalPlugins || [];
babelRC.presets[0][1].additionalPlugins.push("babel-plugin-external-helpers");
// Istanbul code coverage
var coverage = false;
if (process.env.COVERAGE === "true") coverage = true;
if(coverage) {
babelRC.presets[0][1].additionalPlugins.push("babel-plugin-istanbul");
}
// Attempt to determine if a module is external and should not be rolled into
// the bundle. Check for presence in source path, presence of "." in module path,
// or special module paths.
function isExternal(modulePath) {
// "babelHelpers" must be treated as internal or babel-plugin-external-helpers will break
if(/babelHelpers/.test(modulePath)) return false;
// "." in module path = internal
if(/\.\//.test(modulePath)) return false;
// Otherwise, attempt to figure out whether the module is inside the source tree.
modulePath = path.resolve(modulePath)
return !(srcPathRegex.test(modulePath));
}
var getPlugins = () => [
resolve({
extensions: ['.js', '.lsc']
}),
babel(babelRC)
]
var withFormat = (format) => ({
input: 'src/index.lsc',
output: {
file: format === "cjs" ? `lib/index.js` : `lib/index.${format}.js`,
format: format,
exports: 'named',
sourcemap: true
},
plugins: getPlugins(),
external: isExternal
})
// Only build CJS
var formats = [withFormat("cjs")];
export default formats;