This is a simplified version of the build setup that I use - its a modified version of the rollup.js
setup that three.js uses, that compiles ES6 with babel, reads .glsl
files that can contain glslify imports and allows importing examples as modules with minimal modification to the code.
It’s just a rollup config, but it can easily be modified for use with gulp as well - if anybody is interested I can post a gulpfile.js version as well.
Node modules required
- glslify
- rollup
- rollup-plugin-babel
- babel-preset-es2015-loose-rollup ( the ‘loose’ version may sometimes be faster apparently - I haven’t tested this )
Install all of these with
npm install --save-dev glslify rollup rollup-plugin-babel babel-preset-es2015-loose-rollup
Optional npm modules
( I’ll let you figure out if you need these yourself )
- rollup-plugin-commonjs
- rollup-plugin-node-resolve
- rollup-watch (allows you to watch for changes with the
-w
flag)
Install these as needed with
npm install --save-dev rollup-plugin-commonjs rollup-plugin-node-resolve rollup-watch
Rollup config file
Next create a file called rollup.config.js
in your project root:
Run rollup with:
rollup -c -w
(the -c
flag tell it to use the config file, -w
is to watch for changes if using rollup-watch
)
The code above will look for an (ES6) entry point in js/src/main.js
and output an ES5 compatible file suitable for inclusion in a <script>
tag to js/main.js
.