Code Monkey home page Code Monkey logo

ts-aframe-boilerplate's Introduction

A-Frame Boilerplate with TypeScript

NOTE 28 Dec 2022: This repo hasn't been actively maintained for a while (it's still on aframe 0.8) and I don't plan on upating it, so I've placed it into Archive/read-only mode.

Boilerplate for creating WebVR scenes with A-Frame using TypeScript. Based on the original aframe-boilerplate with TypeScript and Webpack goodness added.

Hello World

Getting Started

You can fork this repo to get started, if you'd like to maintain a Git workflow. This repo provides a script (create-new.sh) that helps you quickly stand up a new project based on the boilerplate.

After you have forked this repo, clone a copy of your fork locally and you'll be have your scene ready in these few steps:

git clone https://github.com/sbrudz/ts-aframe-boilerplate.git
cd ts-aframe-boilerplate
./create-new.sh my-new-project
cd my-new-project
npm start

๐Ÿ“ฑ Mobile pro tip: Upon starting the development server, the URL will be logged to the console. Load that URL from a browser on your mobile device. (If your mobile phone and computer are not on the same LAN, consider using ngrok for local development and testing. Browsersync is also worth a gander.)


Developing your scene

The A-Frame best practices recommend putting your application logic in components. This boilerplate sets you up to do that. The src/index.ts file is your entry point to add application logic. There's currently an example component in there. You can either modify what's in there or add more components as separate source files and import those into the index.ts file.

To make changes to the HTML, edit the src/index.html file. When you start the dev server or publish your project, webpack uses this file as a template and adds the generated bundle of code to the header. The generated files all end up in the dist folder.

Note that because the bundle.js file is appended to the header, your DOM won't be ready at the time the file loads so you won't be able to write code that finds HTML elements in the body of your document. Instead, you should wrap your code within an A-Frame component (in the init or update methods). This code will then be run at the correct point in the A-Frame lifecycle.

If you have assets to include, such as textures, place them in the src/assets directory. Webpack will serve these assets up at the /assets location. For example, on your local server, they would be available at http://localhost:3000/assets.

To reduce the generated bundle size, the A-Frame library is marked as an external library in webpack, which means that webpack will not bundle it and instead is expecting A-Frame to be included on the page already. The index.html file is loading it from the aframe.io site. If you want to decouple yourself from depending on an external CDN like this, you can change this behavior by editing webpack.config.js to remove A-Frame from the externals section and putting import 'aframe'; at the top of src/index.ts. After that is done, you'll no longer need to include A-Frame via a script tag in index.html.

Publishing your scene

If you don't already know, GitHub offers free and awesome publishing of static sites through GitHub Pages.

To publish your scene to your personal GitHub Pages:

npm run deploy

And, it'll now be live at http://your_username.github.io/ :)


To know which GitHub repo to deploy to, the deploy script first looks at the optional repository key in the package.json file (see npm docs for sample usage). If the repository key is missing, the script falls back to using the local git repo's remote origin URL (you can run the local command git remote -v to see all your remotes; also, you may refer to the GitHub docs for more information).


Still need Help?

Installation

First make sure you have Node installed.

On Mac OS X, it's recommended to use Homebrew to install Node + npm:

brew install node

To install the Node dependencies:

npm install

Local Development

To serve the site from a simple Node development server:

npm start

Then launch the site from your favourite browser:

http://localhost:3000/

License

This program is free software and is distributed under an MIT License.

ts-aframe-boilerplate's People

Contributors

krzysztof-grzybek avatar sbrudz avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

ts-aframe-boilerplate's Issues

Component methods doesn't rise type errors.

Consider the following example:

AFRAME.registerComponent('hello-world', {
    init: function() {
       const a = this.multiply('customString');
   },

  multiply(myNumber: number) {
    return myNumber * 2;
  }
});

Line
const a = this.multiply('customString');
should throw error, but it doesn't.

Enabling strict mode should fix this problem. (precisely noImplicitThis with this PR).

Would You accept PR?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.