-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
61 lines (56 loc) · 1.71 KB
/
Copy pathrollup.config.js
File metadata and controls
61 lines (56 loc) · 1.71 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
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import copy from 'rollup-plugin-copy';
import typescript from '@rollup/plugin-typescript';
import fs from 'fs';
import path from 'path';
// Custom plugin to generate _headers file
function generateHeaders() {
return {
name: 'generate-headers',
buildEnd() {
// * CORS header for static widget files. The API is protected seperately.
const headers = `/widget/*
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Expose-Headers: Content-Length
Access-Control-Max-Age: 600
`;
const distDir = path.resolve('dist');
if (!fs.existsSync(distDir)) {
fs.mkdirSync(distDir, { recursive: true });
}
fs.writeFileSync(path.join(distDir, '_headers'), headers);
console.log('Generated static cors policy:\n', headers);
}
};
}
// Static assets will vary depending on the application
const copyConfig = {
targets: [
{ src: 'node_modules/@webcomponents', dest: 'dist/node_modules' },
{ src: 'src/widget/index.html', dest: 'dist' },
],
};
// The main JavaScript bundle for modern browsers that support
// JavaScript modules and other ES2015+ features.
const config = {
input: 'src/widget/index.ts',
output: {
dir: 'dist/widget/',
format: 'es',
sourcemap: true,
},
plugins: [
copy(copyConfig),
resolve(),
typescript({ tsconfig: './tsconfig.widget.json' }),
generateHeaders(), // <-- Add the plugin here
],
preserveEntrySignatures: false,
};
if (process.env.NODE_ENV !== 'development') {
config.plugins.push(terser());
}
export default config;