generated from maxwroc/typescript-project-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
95 lines (80 loc) · 2.14 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
87
88
89
90
91
92
93
94
95
import typescript from 'rollup-plugin-typescript2';
import dts from 'rollup-plugin-dts';
import resolve from '@rollup/plugin-node-resolve';
import copy from 'rollup-plugin-copy';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
const iifeFilePath = pkg.main.replace(".es", "");
const filesToCopy = [
{ src: 'src/styles.css', dest: 'dist', rename: pkg.name + '.css' }
];
if (!process.env.RELEASE) {
filesToCopy.push({ src: 'src/styles.css', dest: 'docs', rename: pkg.name + '.css' })
filesToCopy.push({ src: [iifeFilePath, 'dist/*.map'], dest: 'docs' })
}
const plugins = [
copy({
targets: filesToCopy,
hook: 'writeBundle'
}),
resolve(),
typescript({
tsconfigOverride: {
compilerOptions: {
declaration: !!process.env.RELEASE,
declarationDir: "src/dts"
}
},
useTsconfigDeclarationDir: process.env.RELEASE
})
];
let sourcemapPathTransform = undefined;
const additionalBundles = [];
if (process.env.RELEASE) {
plugins.push(
terser({
compress: {}
})
);
let repoRoot = pkg.repository.url
.replace("https://github.com", "https://raw.githubusercontent.com")
.replace(/.git$/, "");
repoRoot += "/";
sourcemapPathTransform = file => repoRoot + "v" + pkg.version + file.substr(2);
// this bundle is the main package bundle (required for import statements from external modules)
additionalBundles.push({
external: [],
input: 'src/index.ts',
output: {
name: "PatternLock",
globals: {},
file: pkg.main,
format: 'es',
sourcemap: false
},
plugins: plugins,
});
// bundling .d.ts files
additionalBundles.push({
input: 'src/dts/index.d.ts',
output: [{ file: "dist/index.d.ts", format: "es" }],
plugins: [dts()]
});
}
export default [
{
external: [],
input: 'src/index.ts',
output: {
name: "PatternLock",
globals: {},
file: iifeFilePath,
format: 'iife',
sourcemap: false, // TODO fix mappings
sourcemapExcludeSources: true,
sourcemapPathTransform: sourcemapPathTransform
},
plugins: plugins,
},
...additionalBundles
];