-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
77 lines (69 loc) · 2.48 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
import copy from 'rollup-plugin-copy'
import rimraf from 'rimraf';
import { join } from 'path';
import { terser } from 'rollup-plugin-terser';
import rollbarDeploy from 'rollup-plugin-rollbar-deploy';
import rollbarSourcemaps from 'rollup-plugin-rollbar-sourcemaps';
import { execSync } from 'child_process';
import createHTMLPlugin from './lib/create-html';
import { version } from './package.json';
require('dotenv').config()
const rollbarClientToken = process.env.ROLLBAR_CLIENT_TOKEN;
const rollbarServerToken = process.env.ROLLBAR_SERVER_TOKEN;
const SOURCE_VERSION = process.env.SOURCE_VERSION || execSync('git rev-parse --short HEAD').toString();
const USER = execSync('whoami').toString();
const distDir = join('public_html');
// Remove ./dist
rimraf.sync(distDir);
function buildConfig({ watch, isProduction } = {}) {
const isDev = watch;
return {
input: {
main: 'src/client/index.js',
},
output: {
dir: distDir,
format: 'iife',
sourcemap: watch || 'hidden',
entryFileNames: '[name]-[hash].js',
chunkFileNames: '[name]-[hash].js',
},
watch: { clearScreen: false },
plugins: [
// resolves in-built node packages like https / fs etc..
// nodeResolve({
// preferBuiltins: true,
// mainFields: ['browser', 'module', 'main'],
// }),
// commonjs(), // allows import to work with commonjs modules that do a module.exports
// globals(),
// builtins(),
// babel({ exclude: 'node_modules/**' }),
!isDev && terser(), // uglify the code if not dev mode
createHTMLPlugin({ isDev, rollbarClientToken }), // create the index.html
copy({
targets: [
{ src: 'src/client/static/*', dest: distDir, dot: true },
],
}),
// createServiceWorkerPlugin(),
// createNumberSolverWorkerPlugin(),
isProduction && rollbarSourcemaps({
accessToken: rollbarServerToken,
baseUrl: '//inthehat.herokuapp.com/',
version,
}), // upload rollbar source maps if production build
isProduction && rollbarDeploy({
accessToken: rollbarServerToken,
revision: SOURCE_VERSION,
environment: 'production',
localUsername: USER,
}), // notify Rollbar of a deployment if production build
].filter(item => item), // filter out unused plugins by filtering out false and null values
};
}
export default function ({ watch }) {
return [
buildConfig({ watch, isProduction: !!process.env.PRODUCTION }),
];
}