You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fast development experience by loading TS files directly in the browser (with typescript-plugin), type-checking concurrently in IDE or in CLI with watch mode, no intermediate JS files transpilation, gives you speed as there is no transpilation or bundling step required _(bundling & transpilation expected only to create app.js & vendor.js bundles for production)_
24
-
(animated gif placeholder...)
25
-
26
-
### WRITE TESTS IN TYPESCRIPT
27
-
Write tests in TypeScript - no transpilation required, running directly from TS source files in a command line (`npm test`).
28
-
Test harness using (Tape)[https://github.com/substack/tape] also with Promise support from (blue-tape)[https://github.com/spion/blue-tape]
29
-
(animated gif placeholder...)
22
+
### RAPID-SPEED DEVELOPMENT WORKFLOW - TypeScript source file hot-reload and in-the-browser transpilation
23
+
Super-fast development experience by loading TypeScript source files directly in the browser (using (plugin-typescript)[https://github.com/frankwallis/plugin-typescript]) while seperately type-checking them in the IDE or in the command-line in watch mode, without transpilation for intermediate JS files or bundling.
24
+
Joined together with single-file hot-reload gives you almost instant feedback-loop as there is no costly project-wide transpilation or bundling step involved.
30
25
31
-
### RELIABLE-HOT-RELOAD
32
-
Local HTTP dev server with hot-reload out-of-the-box - highly reliable and scalable for speed with increasing modules count (explained in [Pros & Cons](#pros--cons)...)
33
-
(animated gif placeholder...)
26
+
### SCALABLE-HOT-RELOAD
27
+
Local HTTP dev server with hot-reload out-of-the-box - highly reliable leveraging SystemJS import feature and scalable for speed with increasing modules count using (systemjs-hot-reloader)[https://github.com/capaj/systemjs-hot-reloader]
28
+
It can load each src file separately eliminating extra bundling step. First it will delete old module from the SystemJS registry and then re-imports updated module with additional modules which have imported the updated module, ensuring to always have the latest changes.
29
+
This approach gives you great scalability with increasing modules count as you reload only necessary modules.
34
30
35
31
### NO-IDE-NO-PROBLEM
36
32
If you are coding in a NO-IDE environment (notepad/vim) or expecting to have a common way across a team to target a specific version of typescript compiler even while using different Editors/IDEs, you can utilize __CLI type-checking workflow__ using `tsc -p src --watch` command for fast incremental type-checking or `tsc -p src` command for project-wide type-check, there is no JS emit so it will not clutter your project or disrupt different build processes based on various IDE plugins or gulp/grunt based tasks.
37
-
(animated gif placeholder...)
38
33
39
34
### CSS-MODULES WITH TYPED CLASS-NAMES
40
-
My concept to achieve locally scoped CSS styles with some TypeScript enhancements using (csjs)[https://github.com/rtsao/csjs#faq]
41
-
Full CSS support with all features like pseudo-classes & media queries, encapsulated in ES6 modules can be easily imported by your UI components.
42
-
BONUS: statically typed class names - solid auto-completion, type-checking, easy refactoring. You can also add doc comments and auto-generate docs of your styles library for your team or utilize some powerful IDE support.
43
-
EXAMPLE: (about-container component)[src/containers/about-container/index.tsx] and it's (about-styles css-module)[src/containers/about-container/about-styles.tsx]
35
+
Own concept to achieve locally scoped CSS styles with statically typed CSS class-names using TypeScript.
36
+
-Full CSS support with pseudo-classes & media queries, encapsulated in ES6 Modules that can be nicely imported by your UI components.
37
+
- Define interfaces with your CSS classes and you get className property type-checking, solid auto-completion and easy refactoring. You can also add doc comments and auto-generate docs of your styles library for your team and utilize IntelliSense features of your IDE.
38
+
EXAMPLE: (css-modules-container component)[src/containers/about-container/index.tsx] and it's (about-styles css-module)[src/containers/about-container/about-styles.tsx]
44
39
(animated gif placeholder...)
45
40
41
+
### ASYNC/AWAIT/GENERATORS transformation when targeting ES3/ES5 (without Babel)
42
+
Many TS boilerplates are using Babel transpilation step after the TypeScript compiler output to get support for "async & generator functions transformation" when targeting ES3/ES5. This is costly process and introduces additional build step into the build workflow.
43
+
My solution promote using only (Facebook Regenerator Project)[https://github.com/facebook/regenerator] (Babel internally doing the same!) which is executed only when running build for production. Use CLI command `npm run regenerator` after building for production.
44
+
__NOTE: This is the same as Babel, because Babel is using "regenerator runtime" internally for async/generator functions transformations. So, why in the TS world we shouldn't be doing the same?__ (reference: https://babeljs.io/docs/usage/caveats/)
45
+
__NOTE (06/10/2016): As TypeScript Team have dropped adding support for downlevel (ES3/ES5) generator transformation in the near future, I believe this is the most optimal solution to use at the moment__ (reference: https://github.com/Microsoft/TypeScript/issues/3975#issuecomment-250859415)
46
+
46
47
## Features
47
48
48
49
- PRODUCTION-WORKFLOW - npm scripts for production bundling & deployment, github-hooks, linter, test runner etc.
@@ -52,6 +53,8 @@ EXAMPLE: (about-container component)[src/containers/about-container/index.tsx] a
52
53
- REDUX-DEV-TOOLS - installed Redux DevTools capabilities with [chrome-extension](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd)
53
54
- IMMUTABLE-STORE - using `seamless-immutable` for simplicity and backwards-compatibility with vanilla JS (no hassle with `toJS()`, `get()`, `getIn()` in your containers and components)
54
55
- BEM & ITCSS - using BEM with Inverted Triangle conventions to give meaning and context to CSS classes
56
+
- EASY TESTING IN TYPESCRIPT - write your tests only in TypeScript - don't worry about transpilation, easily import and run your TS source files from a command line (use `npm test` CLI command).
57
+
Test harness with (Tape)[https://github.com/substack/tape] with Promise support from (blue-tape)[https://github.com/spion/blue-tape]
55
58
56
59
#### React Best Practices & Optimizations
57
60
- no mixins -> use ES6 style PureRenderMixin with PureComponent
@@ -105,26 +108,21 @@ Check yourself using this easy test procedure:
105
108
106
109
## Pros / Cons
107
110
108
-
-If you are depending on TypeScript compiler built-in into the editor/IDE you're using, you can experience some issues and limitations because of older compiler version over which you don't have control. Instead you should depend on a local npm TypeScript installation included in project. Visual Studio Code and alm.tools allows the possibility to use local TS npm package.
109
-
In case you want to stick to using IDE with "baked-in TS" you could turn off it's compilation process and check your types in command line with either `npm run tsc` or `npm run tsc:watch` commands for one-time or continuous-incremental type-checking.
111
+
-be aware that using TypeScript compiler built-in into the editor/IDE like in WebStorm, can give you some trouble because of compiler version over which you don't have any control. Instead you should depend on a local npm TypeScript installation included in project. Visual Studio Code and alm.tools allows the possibility to use a locally installed TS package in your project.
112
+
In case you want to stick to using IDE with "baked-in TS" you could turn off it's compilation process and run type-checking from a command line utilizing provided helper scripts `npm run tsc` or `npm run tsc:watch` commands for one-time check or a continuous-incremental type-checking.
110
113
111
114
- During development there is no need to emit intermediate JS files, this workflow will load your TS files directly in-browser, otherwise you'll lose Hot-Reload capability (new files emitted after each change) and experience much slower workflow without any advantages.
112
115
113
-
- A lot of boilerplates add Babel transpilation step into their dev-workflow with TypeScript, which introduces additional costly build step which slows you down, this workflow only adds async/generators transform (Babel internally doing the same!) only during creation of production bundle (not during development, so it is fast)
114
-
__It's worth to know that Babel is similarly using regenerator internally for async/generators transform__ (https://babeljs.io/docs/usage/caveats/)
115
-
116
-
- SystemJS vs Webpack Hot-Module-Reload: SystemJS hot-reloading works differently from Webpack HMR, it loads each src file separately so there is no need for bundling step. During hot-reload it delete updated module from the System registry and re-imports it and other modules that import this module, ensuring to always have the latest changes.
117
-
This approach gives you great scalability with increasing modules count as you reload only concerned modules and it is also very reliable because of it's simple concept.
118
-
119
-
- If you are using async/generator functions for production and want to transpile to ES5 for old browsers support, you can use `npm run regenerator` command. (I'm working to provide alternative solution which will use typescript@next nightly release.)
120
-
121
116
---
122
117
123
118
## Project Structure
124
119
125
120
```
126
121
.
127
122
├── assets # static assets copied to dist folder
123
+
├── configs # dev / prod bundle config
124
+
| ├── vendor.config.dev.js # packages included in "vendor" bundle for dev
125
+
| └── vendor.config.prod.js # packages included in "vendor" bundle for prod
128
126
├── src # app source code
129
127
│ ├── components # global reusable presentational components
@@ -166,10 +162,11 @@ This approach gives you great scalability with increasing modules count as you r
166
162
167
163
---
168
164
169
-
## Usage
165
+
## Workflows Guide
166
+
__NOTE: Use index.prod.html for production, it have slightly different loading logic. Add references to your static assets like links/scripts and copy to the dist folder during a build process.__
170
167
171
-
#### Dev Workflow
172
-
1.`npm run bundle-dev` - bundle vendor packages for development _(re-run only when app dependencies has changed)_
168
+
#### Development Workflow
169
+
1.`npm run bundle-dev` - create bundle of vendor packages to speed-up full-page reload during development _(re-run only when project dependencies has changed)_
173
170
2.`npm start` - browser will open automatically
174
171
175
172
#### NO-IDE Workflow - command line type checking
@@ -178,10 +175,10 @@ This approach gives you great scalability with increasing modules count as you r
178
175
179
176
#### Build for Production Workflow
180
177
1.`npm run build` - create app.js & vendor.js bundles in 'dist' folder
181
-
-`npm run build:app` - build only app.js bundle _(run when app source code has changed)_
182
-
-`npm run build:vendor` - build only vendor.js bundle _(run when app dependencies has changed)_
178
+
-`npm run build:app` - build only app.js bundle _(run when project source code has changed)_
179
+
-`npm run build:vendor` - build only vendor.js bundle _(run when project dependencies has changed)_
183
180
2. open `http://localhost/dist/` - check prod build on local server
184
-
181
+
3.`npm run regenerator` - if you want to add "async/generator functions" downlevel transformation - use when targeting ES3/ES5
185
182
---
186
183
187
184
## CLI Commands
@@ -194,19 +191,23 @@ This approach gives you great scalability with increasing modules count as you r
194
191
195
192
`npm run tsc:watch` - start TypeScript CLI in watch mode for fast incremental type-checking (`/src` folder)
196
193
197
-
`npm run bundle-dev` - build vendor packages in single file bundle for quick full-page reload __(app sources remain as seperate modules for on-the-fly HMR & transpilation)__
194
+
#### Dev Bundling (`temp/` folder)
198
195
199
-
`npm run unbundle` - delete vendor bundle package __(WARNING: it will result in loading all of vendor packages as seperate requests - use it only if you know what you are doing e.g. when experimenting with HTTP/2 multiplexing/pipelining)__
196
+
`npm run build:dev` - build vendor packages into vendor.dev.js bundle to speed-up full-page reload during development - non-minified with source-maps (dev bundle)
197
+
198
+
`npm run unbundle` - delete vendor.dev.js bundle package __(WARNING: it will result in loading all of vendor packages as seperate requests - use it only if you know what you are doing e.g. when leveraging HTTP/2 multiplexing/pipelining)__
200
199
201
200
#### Production Bundling (`dist/` folder)
202
201
203
-
`npm run build` - build both app & dependecy bundle
202
+
`npm run build` - build both app.js & vendor.js bundle for production
203
+
204
+
`npm run build:app` - build app source code into app.js (prod bundle) - minified, no source-maps
204
205
205
-
`npm run build:app` - build app sources bundle (only app source code) - minified, no source-maps
206
+
`npm run build:vendor` - build vendor packages into vendor.prod.js (prod bundle) - minified, no source-maps
206
207
207
-
`npm run build:vendor` - build app dependencies bundle (only vendor dependencies) - minified, no source-maps
208
+
`npm run build:debug` - build app source code into app.js (dev bundle) - non-minified with source-maps
208
209
209
-
`npm run build:debug` - build app sources bundle - non-minified version with source-maps
210
+
`npm run regenerator` - transpile your app.js through regenerator for async/generator functions when targeting ES3/ES5
210
211
211
212
#### Initialization
212
213
@@ -230,8 +231,6 @@ This approach gives you great scalability with increasing modules count as you r
230
231
231
232
`npm run prepush` - pre push git hook - runs linter and tests
232
233
233
-
`npm run regenerator` - transpile your app.js through regenerator
0 commit comments