0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

webpackでtypescriptをjavascriptに変換

Posted at

準備

$ 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)})();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?