This is the main repository of es6console.com. A tool for playing around with ECMAScript 6 to 5 transformers.
- Features
- Requirements
- Application Structure
- Development
- Developer Tools
- Routing
- Testing
- Deployment
- Build System
- Configuration
- Globals
- Styles
- Server
- Production Optimization
- node
^4.5.0
- yarn
^0.17.0
or npm^3.0.0
First, clone the project:
$ git clone https://github.com/matthisk/es6console.git <my-project-name>
$ cd <my-project-name>
Then install dependencies and check to see it works. It is recommended that you use Yarn for deterministic installs, but npm install
will work just as well.
$ npm install # Install project dependencies
$ npm run dev # Compile and launch (same as `npm start`)
While developing, you will probably rely mostly on npm dev
; however, there are additional scripts at your disposal:
npm run <script> |
Description |
---|---|
start |
Serves your app at localhost:8000 . HMR will be enabled in development. |
compile |
Compiles the application to disk (~/dist by default). |
dev |
Same as npm start , but enables nodemon for the server as well. |
test |
Runs unit tests with Karma and generates a coverage report. |
test:dev |
Runs Karma and watches for changes to re-run tests; does not generate coverage reports. |
deploy |
Runs linter, tests, and then, on success, compiles your application to disk. |
deploy:staging |
Same as deploy but overrides NODE_ENV to "development". |
deploy:prod |
Same as deploy but overrides NODE_ENV to "production". |
deploy_lambda |
Same as deploy_lambda but overrides NODE_ENV to "production". |
deploy_lambda:staging |
Same as deploy_lambda but overrides NODE_ENV to "production". |
deploy_lambda:prod |
Same as deploy_lambda but overrides NODE_ENV to "production". |
lint |
Lint all .js files. |
lint:fix |
Lint and fix all .js files. Read more on this. |
.
โโโ bin # Build/Start scripts
โโโ config # Project and build configurations
โโโ public # Static public assets (not imported anywhere in source code)
โโโ server # Express application that provides webpack middleware
โ โโโ main.js # Development Server application entry point
โโโ src # Application source code
โ โโโ index.html # Main HTML page container for app
โ โโโ main.js # Application bootstrap and rendering
โ โโโ components # Global Reusable Presentational Components
โ โโโ containers # Global Reusable Container Components
โ โโโ layouts # Components that dictate major page structure
โ โ โโโ CoreLayout.js # CoreLayout which receives children for each route
โ โ โโโ CoreLayout.scss # Styles related to the CoreLayout
โ โ โโโ index.js # Main file for layout
โ โโโ routes # Main route definitions and async split points
โ โ โโโ index.js # Bootstrap main application routes with store
โ โ โโโ Home # Fractal route
โ โ โ โโโ index.js # Route definitions and async split points
โ โ โ โโโ assets # Assets required to render components
โ โ โ โโโ components # Presentational React Components
โ โ โ โโโ routes ** # Fractal sub-routes (** optional)
โ โโโ store # Redux-specific pieces
โ โ โโโ createStore.js # Create and instrument redux store
โ โ โโโ reducers.js # Reducer registry and injection
โ โโโ styles # Application-wide styles (generally settings)
โโโ lambda # AWS Lambdas
โโโ tests # Unit tests
To add a unit test, simply create a .spec.js
file anywhere in ~/tests
. Karma will pick up on these files automatically, and Mocha and Chai will be available within your test without the need to import them. Coverage reports will be compiled to ~/coverage
by default. If you wish to change what reporters are used and where reports are compiled, you can do so by modifying coverage_reporters
in ~/config/project.config.js
.
ES6Console is hosted on Amazon S3. When running npm run deploy
the ~/dist
folder is synced up to the s3 bucket configured in config/environment.config.js
. The website requires several backend scripts which are hosted on AWS Lambda using the serverless framework. When running npm run deploy_lambda
these lambdas are automatically deployed.
Default project configuration can be found in ~/config/project.config.js
. Here you'll be able to redefine your src
and dist
directories, adjust compilation settings, tweak your vendor dependencies, and more. For the most part, you should be able to make changes in here without ever having to touch the actual webpack build configuration.
If you need environment-specific overrides (useful for dynamically setting API endpoints, for example), you can edit ~/config/environments.config.js
and define overrides on a per-NODE_ENV basis. There are examples for both development
and production
, so use those as guidelines. Here are some common configuration options:
Key | Description |
---|---|
dir_src |
application source code base path |
dir_dist |
path to build compiled application to |
server_host |
hostname for the Express server |
server_port |
port for the Express server |
compiler_devtool |
what type of source-maps to generate (set to false /null to disable) |
compiler_vendor |
packages to separate into to the vendor bundle |
Webpack is configured to make use of resolve.root, which lets you import local packages as if you were traversing from the root of your ~/src
directory. Here's an example:
// current file: ~/src/views/some/nested/View.js
// What used to be this:
import SomeComponent from '../../../components/SomeComponent'
// Can now be this:
import SomeComponent from 'components/SomeComponent' // Hooray!
These are global variables available to you anywhere in your source code. If you wish to modify them, they can be found as the globals
key in ~/config/project.config.js
. When adding new globals, make sure you also add them to ~/.eslintrc
.
Variable | Description |
---|---|
process.env.NODE_ENV |
the active NODE_ENV when the build started |
__DEV__ |
True when process.env.NODE_ENV is development |
__PROD__ |
True when process.env.NODE_ENV is production |
__TEST__ |
True when process.env.NODE_ENV is test |
Both .scss
and .css
file extensions are supported out of the box. After being imported, styles will be processed with PostCSS for minification and autoprefixing, and will be extracted to a .css
file during production builds.
Babel is configured to use babel-plugin-transform-runtime so transforms aren't inlined. In production, webpack will extract styles to a .css
file, minify your JavaScript, and perform additional optimizations such as module deduplication.