forked from resoai/TileBoard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
93 lines (89 loc) · 2.74 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
import packageJson from './package.json';
import progress from 'rollup-plugin-progress';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-cpy';
import del from 'rollup-plugin-delete';
import emitEJS from 'rollup-plugin-emit-ejs';
import resolve from '@rollup/plugin-node-resolve';
import serve from 'rollup-plugin-serve';
import styles from 'rollup-plugin-styles';
import { terser } from 'rollup-plugin-terser';
const isProduction = process.env.PRODUCTION === 'true';
const outDir = 'build';
let outputJsName = '';
let outputCssName = '';
const appPlugins = [];
if (isProduction) {
outputJsName = 'app-[hash].js';
outputCssName = 'styles-[hash][extname]';
appPlugins.push(terser());
} else {
outputJsName = 'app.js';
outputCssName = 'styles[extname]';
appPlugins.push(serve({
contentBase: outDir,
port: 8080,
}));
}
/** @type {import('rollup').RollupOptions} */
const config = {
input: './scripts/index.js',
output: {
// Defines the output path of the extracted CSS.
assetFileNames: `styles/${outputCssName}`,
dir: outDir,
entryFileNames: `scripts/${outputJsName}`,
format: 'iife',
globals: {
'@babel/runtime/regenerator': 'regeneratorRuntime',
},
name: 'TileBoard',
sourcemap: true,
},
plugins: [
// Clean up output directory before building.
del({
targets: [
`${outDir}/assets/`,
`${outDir}/scripts/app*`,
`${outDir}/styles/styles*`,
],
}),
progress(),
commonjs(),
resolve(),
babel({
babelHelpers: 'bundled',
exclude: 'node_modules/**',
}),
styles({
// Extract CSS into separate file (path specified through output.assetFileNames).
mode: 'extract',
// Don't try to resolve CSS @imports.
import: false,
sourceMap: true,
minimize: isProduction,
url: {
hash: 'assets/[name]-[hash][extname]',
// The public path where assets referenced from css files are available.
publicPath: '../assets/',
},
}),
emitEJS({
src: '.',
data: {
VERSION: packageJson.version,
},
}),
copy([
{ files: './favicon.png', dest: `./${outDir}/` },
{ files: './manifest.webmanifest', dest: `./${outDir}/` },
{ files: './images/*.*', dest: `./${outDir}/images/` },
// Copy over empty custom.css but don't overwrite in case user has customized it.
{ files: './styles/custom.css', dest: `./${outDir}/styles/`, options: { overwrite: false } },
]),
...appPlugins,
],
};
export default config;