準備
$ yarn init -y
$ yarn add -D webpack webpack-cli
$ yarn add -D typescript ts-loader
index.tsを用意
src/index.ts
let a : number = 0
console.log(a)
tsconfig.jsonを作成
$ npx tsc --init
webpack.config.jsでts-loader適用する
webpack.config.js
module.exports = {
entry: path.resolve(__dirname, 'src', 'index.ts'),
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js',
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
}
],
},
resolve: {
extensions: [ '.ts', '.js'],
},
}
ビルド
$ npx webpack
結果
dist/main.js
(()=>{"use strict";console.log(0)})();