This repository has been archived by the owner on Nov 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 278
/
rollup.config.js
117 lines (112 loc) · 3.43 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
import packageJson from './package.json';
import progress from 'rollup-plugin-progress';
import mergeCopy from 'rollup-plugin-copy-merge';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy-glob';
import del from 'rollup-plugin-delete';
import emitEJS from 'rollup-plugin-emit-ejs';
import html from 'rollup-plugin-html';
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 BUNDLED_LOCALES = ['da', 'de', 'en-gb', 'en-us', 'es', 'fr', 'it', 'nl', 'pl', 'pt', 'ru'];
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*`,
`${outDir}/locales/`,
],
}),
progress(),
commonjs({ ignoreTryCatch: false }),
resolve(),
babel({
babelHelpers: 'bundled',
exclude: [
'node_modules/**',
'scripts/directives/*.html',
],
}),
html({
include: 'scripts/directives/*.html',
}),
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: './favicon.svg', dest: `./${outDir}/` },
{ files: './scripts/ServiceWorker.js', dest: `./${outDir}/` },
{ files: './manifest.webmanifest', dest: `./${outDir}/` },
{ files: './images/*.*', dest: `./${outDir}/images/` },
]),
mergeCopy({
targets: BUNDLED_LOCALES.map(locale => {
return {
src: [
`./node_modules/angular-i18n/angular-locale_${locale}.js`,
`./node_modules/moment/locale/${locale}.js`,
],
file: `./${outDir}/locales/${locale}.js`,
};
}),
}),
...appPlugins,
],
};
export default config;