Code Monkey home page Code Monkey logo

spark-ar-babel-boilerplate's Introduction

Overview

This is a boilerplate that compile ES2016 and higher to SparkAR via Babel 7.10 + Webpack.

async function

You can use async function to replace Promise's then chain in SparkAR v85 or higher.

const Scene = require('Scene')
const Diagnostics = require('Diagnostics')

async function start() {
  const plane0 = await Scene.root.findFirst('plane0')
  Diagnostics.log(plane0.name)
}

start()

// print 'plane0' in SparkAR console

babel v7.10

The boilerplate used babel 7.10. So, we can use ES2020's feature like class private properties or optional chaining if need be.

// Class private properies or methods
class Foo {
  #x = 0
  get x() {
    return this.#x
  }
}

const foo = new Foo()

Diagnostics.log(foo.x)   // 0
Diagnostics.log(foo.#x)  // webpack SyntaxError. Private name #x is not defined


// Optional chaining
const obj = { a: 1 }

Diagnostics.log(obj?.a)  // 1
Diagnostics.log(obj?.b)  // null/undefined

Splitting scripts with folder

SparkAR allows to across multiple files, but we can't create folder for script files. By webpack, we can create folder to manage our files.

Installation

  1. Clone or download zip from this repository.
  2. install dependency module from npm
$ npm install
  1. Build it for first running.
$ npm run build

Usage

Development

Watch files from ./src/index.js and auto build our code to ./sparkAR/scripts/script.js. SparkAR will refresh scene.

$ npm run dev

Production

Build a minified file for production.

$ npm run build

spark-ar-babel-boilerplate's People

Contributors

lastor-chen avatar

Watchers

 avatar  avatar

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.