File size: 879 Bytes
8969f81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import resolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import { promisify } from 'util';
import { exec } from 'child_process';
const __exec = promisify(exec);

const PRODUCTION = !!process.env.PRODUCTION;

const OUTFILE_DEV  = `build/bundle.js`;
const OUTFILE_PROD = `build/b${ Date.now() }.min.js`;

(async () => {
	if (! PRODUCTION) {
		return ;
	}
	const outDev  = OUTFILE_DEV .replace(/\//g, '\\/');
	const outProd = OUTFILE_PROD.replace(/\//g, '\\/');
	const sed = process.platform === 'darwin'
		? `sed -i ''`
		: `sed -i''`
	;
	console.log(
		await __exec(`${sed} "s/${ outDev }/${ outProd }/g" views/layout.hbs`)
	);
})();

export default {
	input: `dist/controller.js`,
	output: {
		file: PRODUCTION
			? OUTFILE_PROD
			: OUTFILE_DEV
		,
		format: `iife`,
	},
	plugins: [
		resolve(),
		PRODUCTION ? terser() : undefined,
	]
}