
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
tsc2webpack
Advanced tools
A build tool that calls TypeScript compiler and webpack process sequentially
(Beta) A build tool that calls TypeScript compiler and webpack process sequentially.
Usually, when packing TypeScript files with webpack, using the webpack loader for TypeScript files such as ts-loader
or awesome-typescript-loader
is one of the easiest ways. If you are not familiar with webpack, I recommend to use those loaders instead of tsc2webpack.
tsc2webpack simply executes TypeScript compiler and webpack (watch mode is supported). This intends to speed up execution by compiling all TypeScript files first rather than using loaders, which compiles file by file.
tsc2webpack requires typescript (version: >= 2.7) and webpack (version: 4.x).
npm install -D typescript webpack tsc2webpack
Usage:
tsc2webpack [-p <tsconfig.json>] [-c <webpack.config.js>] [<options...>]
* If tsconfig.json is omitted, tsc2webpack searches 'tsconfig.json'
from the current directory.
* If webpack.config.js is omitted, tsc2webpack loads 'webpack.config.js'
with the expression 'require(path.resolve("webpack.config.js"))'.
Options:
--help, -h, -? Show help and exit [boolean]
--tsconfig, -p, --project The project file or directory for TypeScript
tsconfig.json [string]
--webpackConfig, -c, --conf The webpack configuration JavaScript file
(usually webpack.config.js) [string]
--watch, -w Start watch processes when build finished
[boolean]
--tempBuildDir, --tempDir Temporal output directory for emitted JS files
from TypeScript compiler [string]
--useMemory, --mem Enables 'in-memory temporal build' mode [boolean]
--emitDeclarations, -d Enables to emit declaration files as assets of
webpack [boolean]
--lang, --locale The locale/language for TypeScript messages
[string]
--verbose, -v Enables verbose logging mode [boolean]
--version, -V Show version number and exit [boolean]
Shows the usage.
Specifies the TypeScript project file (such as tsconfig.json) or the directory path.
If omitted, './tsconfig.json'
will be used (same as the TypeScript's tsconfig.json
search process).
NOTE: outDir
compiler option of tsconfig.json
is used for emitted (compiled) JavaScript files unless tempBuildDir
option is specified.
Specifies the webpack configuration JavaScript file (such as webpack.config.js).
If omitted, tsc2webpack executes require(path.resolve('webpack.config.js'))
to load the configuration.
NOTE: before execution, remove loaders for TypeScript files in the webpack configuration (tsc2webpack automatically appends the internal loader to replace TS files).
Specifies if using 'watch' mode (using 'watch' mode of TypeScript compiler and webpack). While both watch processes of TypeScript compiler and webpack will run at the same time, the first build process is executed sequentially (TypeScript -> webpack).
Specifies the temporal output directory for emitted JS files from TypeScript compiler. If specified, this overrides outDir
compiler option of tsconfig.json
.
When webpack process runs, all entry points and modules referring each TypeScript source files in tsconfig.json
are replaced by the each JS files in tempBuildDir
.
Enables 'in-memory temporal build' mode, which temporal output data (JS file content) is kept in the memory instead of file system. If the flag is set to true, 'tempBuildDir' is ignored and 'outDir' TypeScript compiler option is also ignored.
Enables to emit declaration files as assets of webpack. Use this flag if some plugins, specified in the webpack configuration, gather declaration files.
NOTE: No declaration files will be emitted unless 'declaration' flag in the tsconfig.json is true.
Specifies the language (locale) for TypeScript compiler messages. (Currently other messages are outputted in English.)
Enables the verbose mode (detailed logs / messages will be outputted).
Shows the version number.
tsc2webpack uses an internal loader for webpack to load TypeScript files as JavaScript files.
If additional loaders such as babel-loader
are necessary, use AdditionalLoadersPlugin
as followings:
const AdditionalLoadersPlugin = require('tsc2webpack').AdditionalLoadersPlugin;
// webpack configuration
module.exports = {
... // existing settings
plugins: [
new AdditionalLoadersPlugin(
// 'head' loaders (optional parameter; can be null)
[{
loader: 'babel-loader',
options: { presets: ['@babel/preset-env'] }
}],
// 'tail' loaders (optional parameter; can be null)
[]
)
]
};
NOTE: In webpack, loaders in 'use' array are applied in reverse order (from tail to head).
In above case, babel-loader
is appended before tsc2webpack's internal loader in the configuration,
and babel-loader
is applied after the internal loader.
tsc2webpack -p ./tsconfig.json -c ./build/webpack.config.js
Type definitions are available in dist/index.d.ts
(defined in package.json). Please refer to the type definitions to see detailed API descriptions.
import {
// functions
execute,
watch,
setWebpackStatsOptions,
createWebpackFunction,
// objects
TypeScriptError,
WebpackError
} from 'tsc2webpack';
execute
, watch
These functions simply executes TypeScript compiler and webpack process. watch
function is for watch mode.
tsconfig
as an object, please see TscConfig
interface.options
, please see Options
interface.This function affects to the loggings. The log messages are only outputted via logInfo
, logVerbose
, and handleError
methods in the handles
object of options
parameter.
This function returns wrapped webpack
function, calling TypeScript compiler before real webpack process. For example, you can specify the return value as a second parameter of webpack-stream
.
These objects are thrown when TypeScript compilation or webpack process is failed with error. handleError
method in the handles
object of options
parameter will may catch the errors, so you can check and see detailed information from properties of the errors.
MIT License
FAQs
A build tool that calls TypeScript compiler and webpack process sequentially
We found that tsc2webpack demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.