-
-
Save Boscop/dcecf5b25e5a2851200c9151319b5435 to your computer and use it in GitHub Desktop.
Revisions
-
mattdesl revised this gist
Sep 6, 2016 . 1 changed file with 11 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,9 +16,17 @@ require('./other.js'); console.log(new THREE.Vector()); ``` ## custom builds If I need to customize ThreeJS (which is very often in production) then I will simply replace `require('three')` with `require('./lib/vendor/three.js')`. ## examples / one-off extension As bad as it sounds, I might just copy the ThreeJS file and replace `THREE.Foo = function()` with `function Foo ()`, then add `module.exports = Foo` at the bottom. This maybe takes 1-2 minutes and tends to be less painful than dealing with build tool junk. ## lots of extensions Sometimes you need a whole bunch of extensions/examples. Instead of converting them all I pretty much give up and just go the standard script-tag way. To KISS I just end up removing the `require('three')` from my index, copying `node_modules/three/build/three.js` to a vendor folder, `npm uninstall three --save` to remove from package.json, and adding some script tags in HTML: @@ -32,6 +40,4 @@ To KISS I just end up removing the `require('three')` from my index, copying `no </body> ``` My project's codebase doesn't change since it already assumes `THREE` is in global scope. -
mattdesl revised this gist
Sep 6, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ This isn't bullet-proof but here's how I've doing things lately: ```js global.THREE = require('three') ``` - Add the `"THREE"` global to your linter (e.g. semistandard/eslintrc) - For the rest of your script(s), code per usual by just assuming `THREE` exists in window/global scope. ```js -
mattdesl revised this gist
Sep 6, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ This isn't bullet-proof but here's how I've doing things lately: ## modular ThreeJS quickie - `npm install three --save` - Include this in your browserify/webpack root script, typically your `index.js`: ```js global.THREE = require('three') ``` -
mattdesl revised this gist
Sep 6, 2016 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,13 +2,13 @@ This isn't bullet-proof but here's how I've doing things lately: ## modular ThreeJS quickie - `npm install three --save` - Include this in your browserify/webpack root: ```js global.THREE = require('three') ``` - Add this global to your linter (e.g. semistandard/eslintrc) - For the rest of your script(s), code per usual by just assuming `THREE` exists in window/global scope. ```js global.THREE = require('three'); -
mattdesl revised this gist
Sep 6, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ This isn't bullet-proof but here's how I've doing things lately: 2. Include this in your browserify/webpack root: ```js global.THREE = require('three') ``` 3. Add this global to your linter (e.g. semistandard/eslintrc) 4. For the rest of your script(s), code per usual by just assuming `THREE` exists in window/global scope. -
mattdesl created this gist
Sep 6, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ This isn't bullet-proof but here's how I've doing things lately: ## modular ThreeJS quickie 1. `npm install three --save` 2. Include this in your browserify/webpack root: ```js global.THREE = require('three') 3. Add this global to your linter (e.g. semistandard/eslintrc) 4. For the rest of your script(s), code per usual by just assuming `THREE` exists in window/global scope. ```js global.THREE = require('three'); require('./other.js'); console.log(new THREE.Vector()); ``` ## adding extensions Sometimes you need something like a ThreeJS extension or loader which isn't on npm. It gets nasty with `browserify-shim` or similar tools... To KISS I just end up removing the `require('three')` from my index, copying `node_modules/three/build/three.js` to a vendor folder, `npm uninstall three --save` to remove from package.json, and adding some script tags in HTML: ```html <body> ... <script src="js/vendor/three.js.js"></script> <script src="js/vendor/some-three-extension.js"></script> <script src="js/bundle.js"></script> ... </body> ``` ## custom builds If I need to customize ThreeJS (which is very often in production) then I will simply replace `require('three')` with `require('./lib/vendor/three.js')` or use a <script> tag.