Skip to content

Instantly share code, notes, and snippets.

@Boscop
Forked from mattdesl/modular-three.md
Created September 22, 2016 19:05
Show Gist options
  • Save Boscop/dcecf5b25e5a2851200c9151319b5435 to your computer and use it in GitHub Desktop.
Save Boscop/dcecf5b25e5a2851200c9151319b5435 to your computer and use it in GitHub Desktop.

Revisions

  1. @mattdesl mattdesl revised this gist Sep 6, 2016. 1 changed file with 11 additions and 5 deletions.
    16 changes: 11 additions & 5 deletions modular-three.md
    Original file line number Diff line number Diff line change
    @@ -16,9 +16,17 @@ require('./other.js');
    console.log(new THREE.Vector());
    ```

    ## adding extensions
    ## 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.

    Sometimes you need something like a ThreeJS extension or loader which isn't on npm. It gets nasty with `browserify-shim` or similar tools...
    ## 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>
    ```

    ## 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.
    My project's codebase doesn't change since it already assumes `THREE` is in global scope.
  2. @mattdesl mattdesl revised this gist Sep 6, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion modular-three.md
    Original 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 this global to your linter (e.g. semistandard/eslintrc)
    - 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
  3. @mattdesl mattdesl revised this gist Sep 6, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion modular-three.md
    Original 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:
    - Include this in your browserify/webpack root script, typically your `index.js`:
    ```js
    global.THREE = require('three')
    ```
  4. @mattdesl mattdesl revised this gist Sep 6, 2016. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions modular-three.md
    Original 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

    1. `npm install three --save`
    2. Include this in your browserify/webpack root:
    - `npm install three --save`
    - 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.
    - 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');
  5. @mattdesl mattdesl revised this gist Sep 6, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions modular-three.md
    Original 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.

  6. @mattdesl mattdesl created this gist Sep 6, 2016.
    36 changes: 36 additions & 0 deletions modular-three.md
    Original 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.