This repository has been archived by the owner on Jan 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
rollup.config.js
131 lines (126 loc) · 3.16 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import typescript from 'rollup-plugin-typescript2';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import multi from '@rollup/plugin-multi-entry';
import copy from 'rollup-plugin-copy';
import { string } from "rollup-plugin-string";
import serve from 'rollup-plugin-serve'
import * as fs from 'fs';
import * as path from 'path';
// This will generate individual JS files
const DIST_COMPONENTS = false;
const BROWSER = 'iife';
const PROD = !process.env.ROLLUP_WATCH;
const TSCONFIG = {
typescript: require('typescript'),
tsconfigOverride: {
compilerOptions: {
module: "esnext",
moduleResolution: "Node",
target: "ES2017",
lib: ["ES2017", "ES5", "ES6", "DOM"],
baseUrl: "src",
sourceMap: true,
experimentalDecorators: true,
strictNullChecks: true,
allowSyntheticDefaultImports: true,
outDir: "dist",
esModuleInterop: true
},
include: [
'src/@types/*',
'src/site/**/*'
],
exclude: [
'src/app/**/*'
]
}
};
// Append to the inputs any outside your project
// ['./node_modules/foo/src/foo/bar.ts']
const inputs = [];
const entries = [];
const srcDir = path.join(__dirname, 'src');
const namespaces = fs.readdirSync(srcDir)
.filter((f) => f.match(/^[a-z]+$/) !== null);
namespaces.forEach((namespace) => {
if (!(namespace === 'site')) {
return;
}
const namespaceDir = path.join(srcDir, namespace);
const components = fs.readdirSync(namespaceDir)
.filter((f) => f.match(/^[a-zA-Z0-9]+$/) !== null);
components.forEach((component) => {
const componentDir = path.join(namespaceDir, component);
const file = path.join(componentDir, `${component}.ts`);
if (fs.existsSync(file)) {
const name = `${namespace}${component[0].toUpperCase()}${component.substr(1)}`;
const input = `./src/${namespace}/${component}/${component}.ts`;
inputs.push(input);
if (DIST_COMPONENTS) {
entries.push({
plugins: [
resolve(),
typescript(TSCONFIG),
string({
include: '**/*.html'
}),
string({
include: '**/*.css'
})
],
input,
output: {
name: `${name}`,
file: `./dist/${name}.js`,
format: BROWSER,
sourcemap: true
}
});
}
} else {
console.error(`Unable to find ${file}!`);
}
});
});
const plugins = [
commonjs(),
resolve(),
typescript(TSCONFIG),
string({
include: '**/*.html'
}),
string({
include: '**/*.css'
}),
multi(),
copy({
targets: [
{ src: 'src/api/*', dest: 'dist/api' },
{ src: 'src/content/*', dest: 'dist/content' },
{ src: 'assets/resources/*', dest: 'assets/resources' },
{ src: 'src/index.html', dest: 'dist' }
]
})
];
if (!PROD) {
plugins.push(
serve({
open: true,
contentBase: 'dist',
port: 3000,
historyApiFallback: true,
historyApiFallback: '/index.html',
})
);
};
export default [
...entries,
{
input: inputs,
output: {
file: './dist/main.js'
},
plugins
}
];