path:
/rollup.config.js
4.07 KB | plain
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 import path from 'path';
import del from 'rollup-plugin-delete';
import copy from 'rollup-plugin-copy';
import { fileURLToPath } from 'url';
import ignore from "rollup-plugin-ignore"
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import commonjsImport from '@rollup/plugin-commonjs';
import summary from 'rollup-plugin-summary';
import { generateSW } from 'rollup-plugin-workbox';
import jsonImport from '@rollup/plugin-json';
import litcssImport from 'rollup-plugin-lit-css';
import { minify as minifyHtml } from 'html-minifier';
import minifyHtmlLiterals from "rollup-plugin-html-literals";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const appName = 'Öffisearch';
const appRepoUrl = 'https://git.ctu.cx/oeffisearch';
const appImprintUrl = 'https://ctu.cx/imprint.html';
const isDevServer = process.env.ROLLUP_WATCH;
const gitVersion = process.env.GIT_VERSION;
const gitCommit = process.env.GIT_COMMIT;
const gitCommitDate = process.env.GIT_COMMITDATE
export default {
input: 'src/main.js',
output: {
dir: 'dist',
sourcemap: !isDevServer ? false : true,
},
preserveEntrySignatures: false,
treeshake: isDevServer ? false : 'recommended',
onwarn: warning => {
if (!warning.ids.some(e => e.includes('node_modules'))) console.error(`(!) ${warning.message}`);
},
plugins: [
del({ targets: [ 'dist/*' ] }),
copy({
targets: [
{ src: 'src/assets/favicon.png', dest: 'dist' },
{ src: 'src/assets/favicon.svg', dest: 'dist' },
{ src: 'src/assets/manifest.json', dest: 'dist',
transform: contents => JSON.stringify(JSON.parse(
contents.toString().replaceAll('{{APP_NAME}}', appName)
))
},
{ src: 'src/assets/index.html', dest: 'dist',
transform: contents => minifyHtml(contents.toString().replaceAll('{{APP_NAME}}', appName), {
collapseWhitespace: true,
removeAttributeQuotes: true,
minifyCSS: true
})
},
]
}),
// Minify HTML template literals
!isDevServer && minifyHtmlLiterals(),
// stub some modules
ignore([ 'http', 'url', 'tls', 'stream', 'assert', 'https-proxy-agent', 'db-hafas-stations', 'events' ]),
replace({
preventAssignment: true,
delimiters: ['', ''],
values: {
'import {createRequire} from \'module\';': '',
'const require = createRequire(import.meta.url);': '',
'process.env.DEBUG': JSON.stringify(),
'process.env.HTTPS_PROXY': JSON.stringify(),
'process.env.HTTP_PROXY': JSON.stringify(),
'process.env.LOCAL_ADDRESS': JSON.stringify(),
},
}),
replace({
preventAssignment: true,
values: {
'node:buffer': 'buffer',
'cross-fetch': path.resolve(__dirname, 'src/shim/cross-fetch.js'),
'isDevServer': isDevServer,
'APP_NAME': JSON.stringify(appName),
'APP_REPOURL': JSON.stringify(appRepoUrl),
'APP_IMPRINTURL': JSON.stringify(appImprintUrl),
'APP_VERSION': JSON.stringify(gitVersion ? gitVersion : `0.0.0-${isDevServer ? 'dev' : 'prod'}`),
'APP_COMMIT': JSON.stringify(gitCommit ? gitCommit : 'unknown'),
'APP_COMMITDATE': JSON.stringify(gitCommitDate ? gitCommitDate : (new Date).toString()),
},
}),
// Resolve bare module specifiers to relative paths
resolve({
browser: true,
preferBuiltins: false,
modulePaths: [ path.resolve(__dirname, 'src/shim') ],
}),
// css import support for lit
litcssImport({ cssnano: true, }),
// commonjs imports
commonjsImport({ transformMixedEsModules: true }),
// json import support
jsonImport(),
// Minify JS
!isDevServer && terser({
ecma: 2021,
module: true,
warnings: true,
}),
// generate service-worker
!isDevServer && generateSW({
swDest: 'dist/sw.js',
globDirectory: 'dist/',
globPatterns: [ '*' ],
clientsClaim: true,
skipWaiting: true,
sourcemap: false
}),
// Print bundle summary
summary({
showMinifiedSize: isDevServer ? true : false,
showGzippedSize: true,
showBrotliSize: true,
}),
]
};