The npm documentation for using ts-loader
suggests installing typescript
. The official Typescript guide in webpack documentation also recommends the same, but without providing a clear explanation. However, I have successfully built everything without having typescript installed. What am I overlooking?
Here is my current setup:
webpack.config.js
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
// mode: 'development',
entry: './src/index.ts',
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader'
}
]
},
output: {
filename: "bundle.js",
},
plugins: [
new HtmlWebpackPlugin(),
new webpack.ProgressPlugin()
]
}
package.json
{
...
"scripts": {
"webpack": "webpack",
"build:dev": "npm run webpack -- --mode development",
"start": "npm run webpack serve -- --mode development"
},
"author": "ranemihir",
"license": "ISC",
"devDependencies": {
"html-webpack-plugin": "^5.5.3",
"ts-loader": "^9.4.4",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
}
}
output:
asset bundle.js 1.3 KiB [compared for emit] (name: main)
asset index.html 233 bytes [compared for emit]
./src/index.ts 111 bytes [built] [code generated]
webpack 5.88.2 compiled successfully in 2099 ms