• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An enjoyable playground for HTML, JavaScript and CSS

web-playground

npm version Build Status codecov.io

web-playground is command line tool for quickly creating prototypes or demos. It requires no configuration or boilerplate. It has builtin preprocessors, bundler and live reloading server. You can create JS, HTML, or CSS files you need on the fly without worrying about tooling at the beginning.

web-playground is never meant to be a tool for developing production ready app. Once the prototype proven to be worthy. You will need to switch gear. That said, web-playground provides shortcut to conveniently bundle everything into a single HTML file to you put it online wherever you want.

Only supports Node >= 4

Give it a try

npm install -g web-playground

# In the directory you want to put your prototypes
# This will create no files, and no file is required at beginning
wpg start

echo "document.write('<h1>Hack the playground!</h1>')" > js.js

You can create and edit js.js, html.html and css.css files. Your browser will update instantly. You can also add a playground.yml by running wpg init to customize the playground for your needs.

Preprocessors

Web Playground supports a variety of preprocessors. To enable one, first run wpg init to create a playground.yml. Then uncomment the appropriate section in it. For example, to enable SCSS, add preprocessor: babel under js in playground.yml:

js:
  preprocessor: babel

Supported preprocessors

Web Playground supports a variety of preprocessors. But only a few are builtin (babel, node-scss, and ejs). This is to speed up installation and improve start up performance.

Supported preprocessors are:

To enable supported external preprocessor, you need to run npm install <processor_package> in the same directory as playground.yml. For example:

To use Less:

  1. Run wpg init to create a playground.yml.
  2. Add preprocessor: less under css in playground.yml.
  3. Run npm install less (no -g) to have Less available in current directory (you will see a node_modules directory).
  4. Run wpg init again to create css.less or you can just create the file yourself.
  5. Run wpg start to start hacking.

CommonJS module

In js.js file, you can require npm installed modules. web-playground will bundle that for you.

# In current directory
npm install react react-dom
// js.js
var React = require('react');
var ReactDOM = require('react-dom');

class MyComponent extends React.Component {
  render() {
    return <div>Hello World</div>;
  }
}

ReactDOM.render(<MyComponent />, node);

Config file

If playground.yml is available in the same directory, web-playground will load it to provide more customizations. Below is the default configurations if no playground.yml file is found.

title: Cat Playground

html:
  #### Available - ejs, jade
  # preprocessor: ejs

js:
  #### Available - babel, coffeescript, typescript
  preprocessor: babel

  #### These scripts will be added in appearance order and before the your js
  # external:
  #   - 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js'

css:
  #### Available - scss, less, stylus
  preprocessor: scss

  #### Available - autoprefixer
  # vender_prefixing: autoprefixer

  #### Available - reset, normalize
  # base: reset

  #### These stylesheets will be added in appearance order and before the your css
  # external:
  #   - 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'

Manual

Usage: wpg [options] [command]

Commands:

  init              create boilerplate files in current directory
  start [options]   load config and start local server
  bundle            bundle all asserts into a single HTML file

Options:

  -h, --help                   output usage information
  -V, --version                output the version number
  -d, --target-dir <dir-name>  target different directory

Bundle

Sometimes you find yourself need to put your awesome work online. You can use the bundle feature of Web Playground. Use wpg bundle flag when you want to publish your playground. It will bundle all your assets into one index.html file, which you can view just like a webpage without web-playground.

Target different directory

When you work on lots of demos, cd into each dir and start Web Playground is frustrating. You can use --target-dir option to specify a different target directory instead of current one. wpg will do exactly the same thing as if it was working on current directory. This is also very convenient when you use separately installed preprocessors or dependent modules. You will only have to install it once in wpg running directory instead of each target directory.

Existing Issues

  • CommonJS bundling only support babel as preprocessor. Need supports for CoffeeScript and TypeScript.
  • Race condition when switching between CommonJS and none CommonJS bundle. Sometime the old watcher might get loaded to browser because it's slower.
  • CommonJS require detection depends on has-require. It doesn't distinguish between code and comments.

More Repositories

1

redux-observable-middleware

Redux middleware for subscribing to observables
JavaScript
58
star
2

redux-chat

Replicate Facebook Flux Chat example with Redux
JavaScript
31
star
3

fun-http

🐡 pure fun(ction) HTTP server in Node.js
TypeScript
28
star
4

PromptPlay

An experiment on visual prompt chaining.
TypeScript
25
star
5

routility

A routing utility to integrate route state into your business logic layer.
JavaScript
25
star
6

TapLabel

A shameless fork of Krelborn/KILabel that replaces auto link detection with manual adding links.
Swift
8
star
7

flux-chat

A fork of Facebook Flux Chat example with modifications to keep it up to date.
JavaScript
7
star
8

Dockership

Scriptable docker management tool build upon Docker remote API.
JavaScript
6
star
9

react-switch-path

Switch component to render React component like switch statement based on object path availability
TypeScript
5
star
10

example-redux-update-nested-props

JavaScript
5
star
11

Avetuc

A Very Easy To Use Client
Swift
3
star
12

River

Reactive stream composer for React application
JavaScript
3
star
13

TwitterLoginExample

A Twitter OAuth login flow example for android application
3
star
14

webpack-loader

JavaScript
2
star
15

redux-react-observable

Efficient and descriptive Redux React binding.
JavaScript
2
star
16

tame-your-callbacks

HTML
2
star
17

lunch-and-learn-css

Vue
2
star
18

sudoku-webapp

A Simple Sudoku Game for Mobile and Desktop
JavaScript
2
star
19

VideoChatRoom

TypeScript
2
star
20

UARK-Bus-Map-Project

To provide an alternative for official campus map web app of University of Arkansas
JavaScript
2
star
21

server-render-single-page-app

CSS
2
star
22

learn-cpp

C++
2
star
23

Twiddr-old

Objective-C
2
star
24

rekrow

Robust distributed worker queue using RabbitMQ to end all the headache
TypeScript
2
star
25

Learnndkbuild

Java
1
star
26

lunchtalk-docker

JavaScript
1
star
27

eslint-config-d6u

JavaScript
1
star
28

webpack-test

JavaScript
1
star
29

learn_ios

Swift
1
star
30

magic-board

Real time MTG life counter for the web
JavaScript
1
star
31

learn-android-3

Java
1
star
32

learn-android-2

Java
1
star
33

AndroidExamples

Java
1
star
34

u17-reader

Read comics on U17.com with no ad only speed.
JavaScript
1
star
35

aws-web-gui

JavaScript
1
star
36

docker-build-layers

Command line helper to simplify building docker images that have multiple layers.
TypeScript
1
star
37

lets-build-a-highly-interactive-search-box-with-rxjs

JavaScript
1
star
38

map-project-2.0

Place Markers on Maps and Calculate Driving Routes
JavaScript
1
star
39

reflux-chat

Replicate Facebook Flux Chat example with Reflux
JavaScript
1
star
40

twitter-collector

School project to collect and analyze tweets.
R
1
star
41

reactdc-rxjs-talk

A talk about RxJS in ReactDC meetup
JavaScript
1
star
42

MultiGradleProject

Java
1
star
43

traffic-lights-practice

JavaScript
1
star
44

learn-android

Java
1
star
45

upload-to-gcloud-storage

JavaScript
1
star
46

LearnAndroid_ReactiveService

Java
1
star
47

kubernetes-zero-downtime-test

JavaScript
1
star
48

LearnAndroidContentProvider

Java
1
star
49

maxcon

Run series of operations in a dependency driven, maximumly concurrent way.
JavaScript
1
star
50

cpp-example-ipc

C++
1
star
51

logcat-gui

C++
1
star
52

headless-chrome

JavaScript
1
star
53

nested-diff

Calculating deep difference for JavaScript objects. Inspired by https://github.com/flitbit/diff
JavaScript
1
star
54

server-rendering-web-app-boilerplate

JavaScript
1
star
55

observe-object-path

Update an object tree by simply dump entire object in and observing changes of keypaths
TypeScript
1
star
56

nodebotsday-dc-button-boxing

Boxing Game with Ardunio + Node.js
JavaScript
1
star
57

import-elasticsearch-document

JavaScript
1
star