-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.js
More file actions
159 lines (143 loc) · 6.61 KB
/
rollup.config.js
File metadata and controls
159 lines (143 loc) · 6.61 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import replace from '@rollup/plugin-replace';
import summary from 'rollup-plugin-summary';
import license from 'rollup-plugin-license';
import alias from '@rollup/plugin-alias';
// import dts from 'rollup-plugin-dts';
const input = { 'pwa-auth' : './base/export/pwa-auth.js' };
const outputs = [
{
dir: './website/javascript',
entryFileNames: '[name].js',
chunkFileNames: '[name]-[hash].js',
format: 'es', // Format Specification: system // umd // cjs // amd // iife // es fallback.
globals: { lodash: '_' }, // Lodash: Global _ for tree-shaking. // jquery: 'jQuery', // jQuery: Global $ assumed loaded externally.
interop: 'compat' // Interop: Handles mixed exports; safe for legacy.
},{
dir: './source',
entryFileNames: '[name].js',
chunkFileNames: '[name]-[hash].js',
format: 'es',
globals: { lodash: '_' },
interop: 'compat'
}
];
// Plugins array: Sequential chain; resolve first for dep discovery, then transforms, then optimize last.
const plugins = [
// dts(),
// nodeResolve(), // Tell Rollup how to find modules in node_modules
alias({
entries: [
{
find: './lit-html/lib/shady-render.js',
replacement: './node_modules/lit-html/lit-html.js',
},
],
}),
/*
typescript({ // TS config: Inline tsconfig overrides; tsconfig.json primary.
tsconfig: './tsconfig.json', // Path to TS config: Defines compilerOptions like target: 'esnext'.
sourceMap: true
}),
*/
replace({
'process.env.NODE_ENV': JSON.stringify('production'), // Fixes Redux/Firebase env issues, optimizes for prod
'import.meta.env.MODE': JSON.stringify('production'), // Fallback for Lit’s env checks
preventAssignment: true,
delimiters: ['', ''] // Replaces raw strings for Lit's dev mode check
}),
resolve({ // Resolve config: browser: true prioritizes web fields; extensions include .ts for TS support.
browser: true, // Use 'browser' in package.json for conditional exports.
extensions: ['.js', '.ts', '.json'] // Explicit extensions: Ensures TS/JS resolution.
}),
commonjs({ // CommonJS config: Dynamic requires handled; extensions align with resolve.
include: /node_modules/, // Scope: Only transform node_modules to avoid double-work on src.
extensions: ['.js', '.ts'] // Match resolve for consistency.
}),
terser({ // Terser config: Uglify options; format for readability in dev (disabled).
compress: { // Compression: Dead-code removal, etc.; defaults aggressive.
drop_console: true // Drop console.*: Reduces size; customize for warnings.
},
format: { // Formatting: Comments preserved if needed.
comments: false // No comments: Full minification.
},
mangle: { // Mangling: Shorten vars; toplevel for global scope.
toplevel: true
},
sourceMap: true // Maps for minified: Essential for prod debugging.
}),
license({
// Deduplicate and collect license comments
banner: {
commentStyle: 'regular', // Use /* */ comments
content: `
pwa-auth
Copyright (c) 2025 Jacek Markiewicz
Licensed under MIT
`
},
thirdParty: {
output: {
file: './LICENSES.txt', // Output licenses to a separate file
template: dependencies => {
// Deduplicate and format license information
const uniqueLicenses = new Map();
dependencies.forEach(dep => {
if (dep.license) {
uniqueLicenses.set(dep.name, {
name: dep.name,
version: dep.version,
license: dep.license,
licenseText: dep.licenseText || 'No license text provided'
});
}
});
return Array.from(uniqueLicenses.values())
.map(dep => `${dep.name}@${dep.version}\n${dep.license}\n${dep.licenseText}\n`)
.join('\n---\n');
}
},
allow: '(MIT OR Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause)' // Only allow common open-source licenses
}
}),
/*
copy({
patterns: ['images/empty.jpg', 'images/favicon.ico'], // Optional: Copy static files to dist
}),
*/
summary()
];
export default {
input,
output: outputs,
plugins
/*, preserveEntrySignatures: false */
};
/*
babel({ // Babel config: Transpile after TS; .babelrc for presets/plugins.
babelHelpers: 'bundled', // Bundle helpers: Includes @babel/runtime in output to avoid external dep.
exclude: 'node_modules/**', // Scope: Only src code; node_modules handled by commonjs.
extensions: ['.js', '.ts'], // Process TS post-compilation.
sourceMaps: true, // Generate maps: Chains with TS for full source debugging.
presets: [
['@babel/preset-env', {
targets:{ browsers: ['last 2 versions', 'not dead'] } // 'defaults', // >0.25% global usage, not dead browsers (Chrome 51+, Firefox 45+, etc.)
// modules: false, // Preserve ESM for tree-shaking
// bugfixes: true, // Fix browser-specific JS bugs
// corejs: 3, // Use core-js for polyfills
// useBuiltIns: 'usage' // Add polyfills only for used ES2024+ features
}]
], // Env preset for targets
plugins: [ // Array: Additional transforms
// '@babel/plugin-transform-class-properties', // Enables class fields; preserves this in props
["@babel/plugin-proposal-decorators", { "version": "2023-11" }]
]
}),
// import { nodeResolve } from '@rollup/plugin-node-resolve';
// import babel from '@rollup/plugin-babel';
// import typescript from '@rollup/plugin-typescript';
// import minifyHTML from '@lit-labs/rollup-plugin-minify-html-literals'; // Minifies Lit HTML templates, Rollup v4 compatible
// import { copy } from '@web/rollup-plugin-copy';
*/