A shared Babel preset for Canopy projects that provides consistent transpilation for TypeScript, React, and modern JavaScript.
- TypeScript Support - Transpiles TypeScript with
@babel/preset-typescript - Modern React - Configured for React 17+ automatic JSX runtime
- ES Module Preservation - Maintains ES modules for optimal tree-shaking
- Runtime Helpers - Uses
@babel/plugin-transform-runtimeto reduce bundle size - Targeted Transpilation - Only applies necessary transforms based on browserslist targets
- Webpack Import Ignoring - Handles Canopy-specific import patterns
Babel core v7 comes bundled, so ensure your project uses Babel 7.x plugins and presets.
yarn add -D babel-preset-canopyCreate a babel.config.js in your project:
module.exports = {
presets: ['babel-preset-canopy']
};- @babel/preset-typescript - TypeScript transpilation
- @babel/preset-react - React JSX transformation
- Uses automatic JSX runtime (no need to import React)
- Development mode enabled when
NODE_ENV=development
- @babel/preset-env - Smart JavaScript transpilation
bugfixes: true- Applies minimal transforms for known issuesmodules: false- Preserves ES modules for bundler optimizationshippedProposals: false- Only stable language features
- @babel/plugin-transform-runtime - Runtime helper optimization
- Reduces code duplication by reusing Babel helpers
- Enables regenerator for async/await support
- Uses ES modules for better tree-shaking
- Requires
@babel/runtimeto be available (provided via import map in Canopy)
- babel-plugin-webpack-import-ignore - Canopy-specific import handling
- Ignores imports matching
@canopytax/pattern during webpack processing
- Ignores imports matching
Browser targets are defined by browserslist-config-canopy. The preset automatically applies only the necessary transforms based on your targets.
The preset automatically detects the environment:
- Development (
NODE_ENV=development): Enables React development mode for better error messages - Production (
NODE_ENV=production): Optimizes for smaller bundle size and performance
This preset handles TypeScript transpilation through Babel, but you should still maintain a tsconfig.json for type checking which should be run separately:
yarn tsc --noEmitMIT