TypeScipt-Webpack项目搭建
参考
一:
npm init
npm install webpack-cli -D
二:npm install ts-loder typescript -D
配置webpack.config.js
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
mode: "development",
entry: "./src/main.ts",
output: {
path: path.resolve(__dirname, "./dist"),
filename: "bundle.js"
},
devServer: {
},
resolve: {
//webpack必须写此加上.ts
extensions: [".ts", ".js", ".cjs", ".json"]
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader'
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: "./index.html"
})
]
}
三:需要tsconfig.json文件
可以自己配置
也可以使用 tsc --init
四:实现webpapck自动打包
npm install webpack-dev-server -D
注意devserver依赖js文件所以在配置webpack.config.js 要加上**.js**
resolve: {
//webpack必须写此加上
extensions: [".ts", ".js", ".cjs", ".json"]
},
npm install html-webpack-plugin -D
|