-
Notifications
You must be signed in to change notification settings - Fork 230
/
rollup.config.js
106 lines (103 loc) · 3.39 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
import glslify from 'rollup-plugin-glslify';
import resolve from '@rollup/plugin-node-resolve';
import scss from 'rollup-plugin-scss';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import del from 'rollup-plugin-delete';
import replace from '@rollup/plugin-replace';
import {wasm} from "@rollup/plugin-wasm";
import sourcemaps from 'rollup-plugin-sourcemaps';
import license from "rollup-plugin-license";
import path from "path"
import fs from "fs"
function copyFiles(from, to, overwrite = false) {
return {
name: 'copy-files',
generateBundle() {
const log = msg => console.log('\x1b[36m%s\x1b[0m', msg);
log(`copy files:`);
if (!fs.existsSync(to)) {
fs.mkdirSync(to, {recursive: true});
}
fs.readdirSync(from).forEach(file => {
const fromFile = `${from}/${file}`;
const toFile = `${to}/${file}`;
if (fs.existsSync(toFile) && !overwrite)
return;
log(`• ${fromFile} → ${toFile}`);
fs.copyFileSync(
path.resolve(fromFile),
path.resolve(toFile)
);
});
}
};
}
function copyFile(from, to, file, overwrite = false) {
return {
name: 'copy-file',
generateBundle() {
const log = msg => console.log('\x1b[36m%s\x1b[0m', msg);
if (!fs.existsSync(to)) {
fs.mkdirSync(to, {recursive: true});
}
const fromFile = `${from}/${file}`;
const toFile = `${to}/${file}`;
if (fs.existsSync(toFile) && !overwrite)
return;
log(`copy file: ${fromFile} → ${toFile}`);
fs.copyFileSync(
path.resolve(fromFile),
path.resolve(toFile)
);
}
};
}
export default {
strictDeprecations: true,
input: 'src/main.js',
output: [
{
name: 'SampleViewerApp',
file: 'dist/GltfSVApp.js',
format: 'esm',
sourcemap: true
}
],
plugins: [
wasm(),
glslify({
include: ['./glTF-Sample-Renderer/source/Renderer/shaders/*', './glTF-Sample-Renderer/source/shaders/*'],
compress: false
}),
resolve({
browser: true,
preferBuiltins: true,
dedupe: ['gl-matrix', 'jpeg-js', 'fast-png']
}),
scss(), // Version 4 is not working
del({ targets: 'dist/*' }),
copyFile(".", "./dist", "index.html", true),
copyFile(".", "./dist", "main.js", true),
copyFiles("./assets/images", "./dist/assets/images", true),
copyFiles("./assets/ui", "./dist/assets/ui", true),
copyFiles("./glTF-Sample-Renderer/source/libs", "./dist/libs", true),
copyFiles("./glTF-Sample-Renderer/assets/images", "./dist/assets/images", true),
replace({
'process.env.NODE_ENV': JSON.stringify('production'), // This resolves an issue with vue
preventAssignment: true,
}),
commonjs(),
sourcemaps(),
license({
banner: {
content: {
file: 'LICENSE_BANNER.txt',
}
},
thirdParty:{
includeSelf: true
}
})
]
};