Top Related Projects
TypeScript loader for webpack
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.
📦 Babel loader for webpack
Rust-based platform for the Web
An extremely fast bundler for the web
Quick Overview
Awesome TypeScript Loader is a TypeScript loader for Webpack that aims to provide faster and more efficient compilation of TypeScript files. It offers advanced features like incremental builds and caching to improve build times in large projects.
Pros
- Faster compilation times compared to ts-loader, especially for large projects
- Supports incremental builds, reducing rebuild times
- Integrates well with Webpack and its ecosystem
- Offers caching mechanisms to further improve performance
Cons
- Less actively maintained compared to ts-loader
- May have compatibility issues with newer versions of TypeScript or Webpack
- Configuration can be complex for advanced use cases
- Some users report occasional stability issues
Getting Started
To use awesome-typescript-loader in your project, follow these steps:
- Install the loader:
npm install --save-dev awesome-typescript-loader
- Configure your
webpack.config.js
:
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
use: 'awesome-typescript-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
};
- Create a
tsconfig.json
file in your project root:
{
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"jsx": "react",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": false,
"noImplicitAny": false,
"noImplicitReturns": false,
"removeComments": true,
"strictNullChecks": false,
"outDir": "dist",
"lib": ["es6", "es7", "dom"]
},
"exclude": ["node_modules"]
}
With these configurations in place, you can now use awesome-typescript-loader to compile your TypeScript files in your Webpack build process.
Competitor Comparisons
TypeScript loader for webpack
Pros of ts-loader
- More actively maintained with frequent updates
- Better integration with webpack's watch mode
- Supports custom transformers out of the box
Cons of ts-loader
- Generally slower compilation times
- Lacks some advanced features like separate type checking
Code Comparison
ts-loader configuration:
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
};
awesome-typescript-loader configuration:
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
},
],
},
};
Both loaders serve the purpose of integrating TypeScript with webpack, but they have different strengths and weaknesses. ts-loader is more actively maintained and offers better integration with webpack's features, while awesome-typescript-loader provides some performance optimizations and additional features like separate type checking.
The choice between the two depends on specific project requirements, such as compilation speed, webpack integration, and the need for advanced features. It's worth noting that awesome-typescript-loader is no longer actively maintained, which may be a significant factor in choosing ts-loader for new projects.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
Pros of TypeScript
- Official Microsoft project with extensive documentation and community support
- Broader scope, covering the entire TypeScript language and tooling ecosystem
- Regular updates and improvements to the core language features
Cons of TypeScript
- Larger and more complex codebase, potentially harder to contribute to
- Not specifically optimized for webpack integration like awesome-typescript-loader
- May require additional configuration for specific build environments
Code Comparison
TypeScript (tsconfig.json):
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true
}
}
awesome-typescript-loader (webpack.config.js):
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader'
}
]
}
}
The TypeScript repository focuses on the core language and compiler, while awesome-typescript-loader is specifically designed as a webpack loader for TypeScript files. TypeScript provides a more comprehensive solution for TypeScript development, including language services and tooling. awesome-typescript-loader, on the other hand, offers a streamlined integration with webpack, potentially providing faster build times in certain scenarios.
While TypeScript is essential for any TypeScript project, awesome-typescript-loader can be a valuable addition for projects using webpack, offering specific optimizations and easier configuration for that build system.
A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.
Pros of webpack
- More comprehensive bundling solution, handling various asset types beyond TypeScript
- Larger ecosystem with extensive plugins and loaders
- Active development and frequent updates
Cons of webpack
- Steeper learning curve due to its complexity and extensive configuration options
- Can be overkill for smaller projects or those focused primarily on TypeScript
Code Comparison
webpack configuration:
module.exports = {
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
};
awesome-typescript-loader configuration:
module.exports = {
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
};
While webpack provides a more comprehensive solution for bundling various assets, awesome-typescript-loader focuses specifically on TypeScript integration. webpack offers greater flexibility and a larger ecosystem, but may be more complex to set up. awesome-typescript-loader provides a simpler configuration for TypeScript-centric projects but lacks the broader asset handling capabilities of webpack.
📦 Babel loader for webpack
Pros of babel-loader
- Broader language support: Handles JavaScript, TypeScript, and other languages
- More active development and larger community
- Extensive plugin ecosystem for additional transformations
Cons of babel-loader
- Slightly slower compilation times for TypeScript projects
- Requires additional configuration for TypeScript support
- May not support all TypeScript-specific features out of the box
Code Comparison
babel-loader configuration:
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-typescript']
}
}
}
]
}
awesome-typescript-loader configuration:
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'awesome-typescript-loader'
}
}
]
}
Both loaders serve similar purposes, but babel-loader offers more flexibility for projects using multiple languages or requiring advanced transformations. awesome-typescript-loader is more focused on TypeScript and may provide better performance for pure TypeScript projects. The choice between the two depends on project requirements and the development team's preferences.
Rust-based platform for the Web
Pros of swc
- Significantly faster compilation and bundling due to Rust implementation
- Broader language support, including JavaScript and TypeScript
- Active development and frequent updates
Cons of swc
- Less mature ecosystem compared to awesome-typescript-loader
- May require additional configuration for complex TypeScript setups
- Potential compatibility issues with some TypeScript-specific features
Code Comparison
awesome-typescript-loader configuration:
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader'
}
]
}
}
swc configuration:
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript'
}
}
}
}
}
]
}
}
Both projects aim to improve TypeScript compilation in webpack environments. awesome-typescript-loader focuses specifically on TypeScript integration, while swc offers a broader range of features and language support. swc's Rust implementation provides significant performance benefits, but it may require more setup for complex TypeScript projects. awesome-typescript-loader has a more established ecosystem for TypeScript-specific use cases.
An extremely fast bundler for the web
Pros of esbuild
- Significantly faster build times due to its Go-based implementation
- Supports a wide range of modern JavaScript and CSS features out of the box
- Simpler configuration and setup process
Cons of esbuild
- Less mature ecosystem and community support compared to awesome-typescript-loader
- May have limited compatibility with certain TypeScript-specific features
- Fewer customization options for advanced use cases
Code Comparison
esbuild:
require('esbuild').build({
entryPoints: ['app.ts'],
bundle: true,
outfile: 'out.js',
}).catch(() => process.exit(1))
awesome-typescript-loader:
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader'
}
]
}
}
Summary
esbuild offers superior performance and simplicity, making it an excellent choice for projects prioritizing build speed and ease of use. However, awesome-typescript-loader provides deeper TypeScript integration and more extensive customization options, which may be crucial for complex TypeScript projects or those requiring specific optimizations. The choice between the two depends on project requirements, team expertise, and the importance of build performance versus TypeScript-specific features.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
TypeScript loader for Webpack
See also:
Installation
npm install awesome-typescript-loader --save-dev
Performance issues
Please note that ATL works the same way as a TypeScript compiler as much as possible. So please be careful with your files
/exclude
/include
sections.
ADVICE: Turn on useCache
option.
ADVICE: Typically you want your files
section to include only entry points.
ADVICE: The loader works faster if you use isolatedModules
or forceIsolatedModules
options.
ADVICE: The loader works faster if you will use reportFiles
to restrict
checking scope.
ADVICE: Use the loader together with hard-source-webpack-plugin
The world is changing, other solutions are evolving and ATL may work slower
for some workloads. Feel free to try ts-loader
with HappyPack
or thread-loader
and hard-source-webpack-plugin.
Differences between ts-loader
awesome-typescript-loader
loader was created mostly to speed-up compilation in my own projects.
Some of them are quite big and I wanted to have full control on how my files are compiled. There are two major points:
-
atl has first-class integration with Babel and enables caching possibilities. This can be useful for those who use Typescript with Babel. When
useBabel
anduseCache
flags are enabled, typescript's emit will be transpiled with Babel and cached. So next time if source file (+environment) has the same checksum we can totally skip typescript's and babel's transpiling. This significantly reduces build time in this scenario. -
atl is able to fork type-checker and emitter to a separate process, which also speeds-up some development scenarios (e.g. react with react-hot-loader) So your webpack compilation will end earlier and you can explore compiled version in your browser while your files are typechecked.
Configuration
- Add
.ts
as a resolvable extension. - Configure all files with a
.ts
extension to be handled byawesome-typescript-loader
.
webpack.config.js
// `CheckerPlugin` is optional. Use it if you want async error reporting.
// We need this plugin to detect a `--watch` mode. It may be removed later
// after https://github.com/webpack/webpack/issues/3460 will be resolved.
const { CheckerPlugin } = require('awesome-typescript-loader')
module.exports = {
// Currently we need to add '.ts' to the resolve.extensions array.
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx']
},
// Source maps support ('inline-source-map' also works)
devtool: 'source-map',
// Add the loader for .ts files.
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader'
}
]
},
plugins: [
new CheckerPlugin()
]
};
After that, you will be able to build TypeScript files with webpack.
NodeJS versions
The loader supports NodeJS 4 and newer.
tsconfig.json
You can use the tsconfig.json file to configure your compiler and loader:
{
"compilerOptions": {
"noImplicitAny": true,
"removeComments": true
},
"awesomeTypescriptLoaderOptions": {
/* ... */
}
}
Supported TypeScript
awesome-typescript-loader@2.x
aims to support only typescript@2.x
and webpack@2x
, if you need old compilers please use
1.x
or 0.x
versions.
Advanced path resolution in TypeScript 2.0
If you want to use new paths
and baseUrl
feature of TS 2.0 please include TsConfigPathsPlugin
.
This feature is available only for webpack@2.1
.
const { TsConfigPathsPlugin } = require('awesome-typescript-loader');
resolve: {
plugins: [
new TsConfigPathsPlugin(/* { configFileName, compiler } */)
]
}
Loader options
silent (boolean) (default=false)
No logging from the checker. Please note that this option disables async error reporting because
this option bans console.log()
usage.
compiler (string) (default='typescript')
Allows use of TypeScript compilers other than the official one. Must be set to the NPM name of the compiler, e.g. ntypescript or the path to a package folder. Note that the compiler must be installed in your project. You can also use nightly versions.
useTranspileModule (boolean) (default=false)*
Use fast transpileModule
emit mode. Disables automatically when you set compilerOption declaration: true
(reference).
instance (string) (default='at-loader')
Allows the use of several TypeScript compilers with different settings in one app. Override instance
to initialize another instance.
configFileName (string) (default='tsconfig.json')
Specifies the path to a TS config file. This is useful when you have multiple config files. This setting is useless inside a TS config file.
transpileOnly (boolean)
Use this setting to disable type checking, enabling this will nullify the CheckerPlugin
usage in your webpack configuration.
errorsAsWarnings (boolean)
Emit all typescript errors as warnings.
forceIsolatedModules (boolean)
Use this setting to disable dependent module recompilation.
ignoreDiagnostics (number[]) (default=[])
You can squelch certain TypeScript errors by specifying an array of diagnostic codes to ignore.
For example, you can transpile stage 1 properties from *.js
using "ignoreDiagnostics": [8014]
.
useBabel (boolean) (default=false)
Invoke Babel to transpile files. Useful with ES6 target. Please see useCache
option
which can improve warm-up time.
If you're using babelOptions
, anything in .babelrc
will take precedence. This breaks expected usage for scenarios where you need two sets of Babel configs (example: one for Webpack, one for your build tools).
You may want to "babelrc": false
to disable .babelrc
if you don't want it:
{
"useBabel": true,
"babelOptions": {
"babelrc": false, /* Important line */
"presets": [
["@babel/preset-env", { "targets": "last 2 versions, ie 11", "modules": false }]
]
},
"babelCore": "@babel/core", // needed for Babel v7
}
babelCore (string) (default=undefined)
Override the path used to find babel-core
. Useful if node_modules
is installed in a non-standard place or webpack is being invoked from a directory not at the root of the project.
For Babel 7, this should be set to "@babel/core"
.
babelOptions (object) (default=null)
Use this option to pass some options to Babel (e.g. presets). Please note that
.babelrc
file is more universal way to do this.
useCache (boolean) (default=false)
Use internal file cache. This is useful with Babel, when processing takes a long time to complete. Improves warm-up time.
usePrecompiledFiles (boolean) (default=false)
Use pre-compiled files if any. Files must be named as {filename}.js
and {filename}.map
.
cacheDirectory (string) (default='.awcache')
Directory where cache is stored.
reportFiles (string[])
Specify globs to report file diagnostics. ALL OTHER ERRORS WILL NOT BE REPORTED. Example:
reportFiles: [
"src/**/*.{ts,tsx}"
]
getCustomTransformers (string | ((program: ts.Program) => ts.CustomTransformers | undefined)) (default=undefined)
Provide custom transformers, TypeScript 2.4.1+. Example:
const styledComponentsTransformer = require('typescript-plugin-styled-components').default;
const keysTransformer = require('ts-transformer-keys/transformer').default;
// ...
rules: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
options: {
// ... other loader's options
getCustomTransformers: program => ({
before: [
styledComponentsTransformer(),
keysTransformer(program)
]
})
}
}
]
Compiler options
You can pass compiler options inside the loader query string or in a TS config file.
Top Related Projects
TypeScript loader for webpack
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.
📦 Babel loader for webpack
Rust-based platform for the Web
An extremely fast bundler for the web
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot