Coder Social home page Coder Social logo

es6-modules-starter's Introduction

#ES6/ES2015 Modules Starter Project

Quick Start

  1. Install the global packages.

    npm install gulp -g

  2. Install the local packages for this demo.

    npm install

  3. Run Gulp:

    gulp

  4. Run the server, launch the browser, and transpile the ES6 to ES5 using Babel

    npm start

Details

The source code is located in the js folder and written in ES6/ES2015. We use gulp to transpile to ES5 using Babel. The gulp command runs the default Gulp task which transpiles the code and puts it in the dist folder and then watches for more changes. If you change the source, it will transpile again.

When you launch index.html (via npm start), SystemJS kicks in and looks for config.js for its settings. We tell SystemJS that the base URL for the code is in /dist. This is important so all import statements that were written assuming relative pathing in the src folder will still work. Finally, we tell SystemJS that import statements by default should assume they end with .js. This is accomplished by setting defaultExtension to js. See the code below for an example.

System.config({
    map: {
      main: 'dist' //Map "main" to the "dist" folder
    },
    packages: {
      //Define settings for loading files in "dist"
      dist: {
        main: 'main.js',
        format: 'system',
        defaultExtension: 'js'
      }
    }
});

We can now import the main starting module (main.js) like this:

System.import('main');

Now SystemJS gets /dist/main.js which in turn imports car and truck. Each of those import auto and extend it. SystemJS knows that the base URL is /dist and to assume an extension of .js, so it really gets /dist/car.js and /dist/truck.js which in turn get /dist/auto.js.

es6-modules-starter's People

Contributors

danwahlin avatar gregdeane avatar johnpapa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

es6-modules-starter's Issues

gulp command hanging.

ive followed install instructions and got to the gulp command.... just hanging... any ideas what may be the problem? thanks.

js840@virtualmin:~/public_html/drupal-8.4.0/app/es6-modules$ gulp
[16:20:04] Using gulpfile ~/public_html/drupal-8.4.0/app/es6-modules/gulpfile.js
[16:20:04] Starting 'babel'...
[16:20:04] Finished 'babel' after 17 ms
[16:20:04] Starting 'watch'...
[16:20:04] Finished 'watch' after 23 ms
[16:20:04] Starting 'default'...
[16:20:04] Finished 'default' after 91 μs

No-compile development experience.

I'm pretty new to javascript (well... relatively) but have a stronger background in .Net.
What I considered as appealing in my early javascript days, was that you could take a bunch of html and .js files and just run it by itself, no compilation or whatsoever required.
Today, this experience is gone, grunt/gulp and transpilers took a first citizen place.
I think it's a pity that part of the simplicity of the javascript development time experience disappeared as such. Especially, since one can observe that with Roslyn, .Net is going the opposite direction (roslyn compiles on the fly as you know). Note, I'm completely happy with taskrunners for minification, deployment, packaging, you name it.

Fortunately, there is also the option to apply in-browser-transpilation.
It could maybe worth including this also in the sample, together with type-script compilation and type-script in-browser compiliation ?
I understand that in browser compilation is only suitable for development time.

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.