-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
rollup.config.js
95 lines (93 loc) · 2.74 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
/**
* Copyright 2020 (c) Felix Palmer
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
import shader from './src/rollup-plugin-shader';
import { string } from 'rollup-plugin-string';
import sucrase from '@rollup/plugin-sucrase';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import rootImport from 'rollup-plugin-root-import';
import visualizer from 'rollup-plugin-visualizer';
import pkg from "./package.json";
const DEV = !!process.env.DEV;
const SHADER_DIR = DEV ? 'shaders' : 'shaders/min';
export default {
input: 'src/index.js',
output: DEV ? {
// Dev build includes extra logging and un-minified shaders and THREE.js is
// imported externally for faster builds
name: 'Procedural',
file: `build/procedural-gl.dev.js`,
format: 'esm',
sourcemap: true
} : [
{
name: 'Procedural',
file: `build/procedural-gl.js`,
format: 'umd',
},
{
file: `build/procedural-gl.module.js`,
format: 'esm',
}
],
treeshake: !DEV,
plugins: [
replace( {
__buildVersion__: `'${pkg.version}'`,
__dev__: DEV
} ),
alias({
entries: [
{ find: 'dat', replacement: 'dat.gui.min' },
{ find: '/gui', replacement: DEV ? '/gui' : '/empty' },
{ find: 'lodash', replacement: 'lodash.min' },
{ find: '@mapbox/tilebelt', replacement: 'tilebelt' },
{ find: 'react', replacement: 'react-compat' },
{ find: 'shader', replacement: `../${SHADER_DIR}` },
{ find: 'three.lib', replacement: 'three.module.js' }
]
}),
resolve( {
extensions: ['.js', '.jsx'],
customResolveOptions: {
moduleDirectory: 'lib'
}
} ),
rootImport({
root: `${__dirname}/src`,
useInput: 'prepend',
// If we don't find the file verbatim, try adding these extensions
extensions: '.js',
}),
shader( { include: `${SHADER_DIR}/**` } ),
commonjs({
include: [
'node_modules/**',
'lib/**'
],
exclude: [
'node_modules/process-es6/**'
]
}),
string( { include: [/\.css$/, /\.json$/, /\.svg$/] } ),
sucrase( {
exclude: [ 'node_modules/**', `${SHADER_DIR}/**` ],
production: true,
transforms: [ 'jsx' ]
} ),
!DEV && visualizer( { gzipSize: true } )
],
onwarn: function ( warning ) {
if ( warning.code === 'THIS_IS_UNDEFINED' ) { return }
console.error(warning.message);
},
// For faster builds, treat three as external in DEV mode
external: DEV ? [ '/lib/three.module.js' ] : []
};