Boss lesson · Unit 02
The build
Type-check, transpile, bundle, minify: follow one project through, then fix a slow and a broken build
What you practise
- Type-check, transpile, bundle, minify
- Source maps
- What a bundler drops and why
- Reading build output and a build that is slow or broken
Try a question from this lesson
Pick one
Browsers run JavaScript and know nothing about type annotations. What must a build do to this TypeScript before a browser can run it?
const price: number = 5;
console.log(price * 2);Correct answer
Remove the annotation, leaving plain JavaScript
Why
A browser would stop at : number with a syntax error. Types exist for the checker and the editor; once checked they are deleted, and what ships is const price = 5;. That rewrite is called transpiling.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Four stages
A build turns the code you write into the code you ship.
Type-check: prove the types agree. Transpile: rewrite into JavaScript the target understands. Bundle: follow every import and join the modules into a few files. Minify: shorten names and strip whitespace.
Each stage has one job, and each can fail on its own.
Concept
Bundling and tree shaking
A bundler starts at the entry file and follows every import, joining the modules it reaches into one file.
Imports and exports are written at the top level and cannot change at run time, so the bundler can see which exports nobody uses and leave them out. That is tree shaking.
Concept
Source maps
Minified code is unreadable, and so are its errors: app.js:1:5731.
A source map is a file the build writes next to the output (app.js.map). It maps every position in the shipped file back to the original file and line, so debuggers and error trackers can show cart.ts:42 instead.
9 more exercises in the app
- 1× order the lines
- 4× multiple choice
- 1× fill the blanks
- 1× type the answer
- 2× true or false
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.