1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00
trois/rollup.config.js

82 lines
2.6 KiB
JavaScript
Raw Normal View History

2021-04-27 01:05:12 +08:00
import path from 'path'
2021-04-22 03:05:49 +08:00
import vue from 'rollup-plugin-vue'
2021-04-27 01:05:12 +08:00
import typescript from 'rollup-plugin-typescript2'
2021-04-22 03:05:49 +08:00
import replace from '@rollup/plugin-replace'
2021-04-27 01:05:12 +08:00
import { terser } from "rollup-plugin-terser"
// ensure TS checks only once for each build
let hasTSChecked = false
2020-09-16 21:30:39 +08:00
2021-04-22 03:05:49 +08:00
const input = 'src/export.ts'
2021-04-27 01:05:12 +08:00
2020-09-17 05:54:14 +08:00
const external = [
'three',
'three/examples/jsm/controls/OrbitControls.js',
2021-02-21 21:10:11 +08:00
'three/examples/jsm/deprecated/Geometry.js',
2021-03-07 22:18:29 +08:00
'three/examples/jsm/lights/RectAreaLightUniformsLib.js',
'three/examples/jsm/helpers/RectAreaLightHelper.js',
2020-10-04 06:49:05 +08:00
'three/examples/jsm/loaders/GLTFLoader.js',
2021-03-14 02:34:34 +08:00
'three/examples/jsm/loaders/FBXLoader.js',
2020-09-17 05:54:14 +08:00
'three/examples/jsm/postprocessing/BokehPass.js',
2020-10-04 06:49:05 +08:00
'three/examples/jsm/postprocessing/EffectComposer.js',
'three/examples/jsm/postprocessing/FilmPass.js',
'three/examples/jsm/postprocessing/HalftonePass.js',
2020-09-17 05:54:14 +08:00
'three/examples/jsm/postprocessing/RenderPass.js',
2021-02-21 21:10:11 +08:00
'three/examples/jsm/postprocessing/Pass.js',
2020-10-04 06:49:05 +08:00
'three/examples/jsm/postprocessing/SAOPass.js',
2021-04-04 03:45:08 +08:00
'three/examples/jsm/postprocessing/SSAOPass.js',
2021-02-21 21:10:11 +08:00
'three/examples/jsm/postprocessing/SMAAPass.js',
'three/examples/jsm/postprocessing/ShaderPass.js',
2020-09-17 05:54:14 +08:00
'three/examples/jsm/postprocessing/UnrealBloomPass.js',
2021-02-21 21:10:11 +08:00
'three/examples/jsm/shaders/FXAAShader.js',
2021-04-05 03:09:29 +08:00
'three/examples/jsm/webxr/VRButton.js',
2020-09-17 05:54:14 +08:00
'vue',
2021-04-22 03:05:49 +08:00
]
2020-10-04 06:49:05 +08:00
2021-03-04 04:49:22 +08:00
const cdnReplaces = {
2021-04-04 03:45:08 +08:00
'from \'vue\'': 'from \'https://unpkg.com/vue@3.0.11/dist/vue.esm-browser.prod.js\'',
'from \'three\'': 'from \'https://unpkg.com/three@0.127.0/build/three.module.js\'',
'from \'three/examples': 'from \'https://unpkg.com/three@0.127.0/examples',
2021-02-26 05:55:44 +08:00
delimiters: ['', ''],
2021-04-22 03:05:49 +08:00
}
2021-02-26 05:55:44 +08:00
2021-04-27 01:05:12 +08:00
function createConfig(format, output, plugins = []) {
const tsPlugin = typescript({
check: false, // !hasTSChecked,
cacheRoot: path.resolve(__dirname, 'node_modules/.tscache'),
tsconfigOverride: {
compilerOptions: {
sourceMap: false, // !hasTSChecked,
declaration: false, // !hasTSChecked,
declarationMap: false, // !hasTSChecked,
},
include: [input],
2020-09-16 21:30:39 +08:00
},
2021-04-27 01:05:12 +08:00
})
hasTSChecked = true
return {
2020-09-16 21:30:39 +08:00
input,
external,
output: {
2021-04-27 01:05:12 +08:00
format,
...output,
// exports: 'named',
2020-09-16 21:30:39 +08:00
sourcemap: true,
},
plugins: [
2021-04-27 01:05:12 +08:00
tsPlugin,
vue(),
2020-09-16 21:30:39 +08:00
...plugins,
],
2021-04-27 01:05:12 +08:00
}
}
export default [
createConfig('es', { file: 'build/trois.module.cdn.js' }, [replace(cdnReplaces)]),
createConfig('es', { file: 'build/trois.module.cdn.min.js' }, [replace(cdnReplaces), terser()]),
createConfig('es', { file: 'build/trois.module.js' }),
createConfig('es', { file: 'build/trois.module.min.js' }, [terser()]),
createConfig('cjs', { file: 'build/trois.js' }),
2021-04-22 03:05:49 +08:00
]