/***
* @Description: webpack配置文件
* @Author: Harry
* @Date: 2021-11-12 16:40:12
* @Url: https://u.mr90.top
* @github: https://github.com/rr210
* @LastEditTime: 2021-11-16 21:42:23
* @LastEditors: Harry
*/
const path = require('path')
const HTMLWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
module.exports = {
mode: "production",
entry: "./src/index.ts",
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
environment: {
arrowFunction: false,
const: false
}
},
resolve: {
extensions: ['.ts', '.js']},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
// 配置指定的加载源
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{
targets: {
"chrome": "58",
"ie": "11"
},
"corejs": '3'
}
]
]
}
},
'ts-loader'
],
exclude: /node_modules/
}, {
test: /\.less$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
[
'postcss-preset-env', {
browsers: 'last 2 versions'
}
]
]
}
}
},
'less-loader'
]
}
],
},
plugins: [
new CleanWebpackPlugin(),
new HTMLWebpackPlugin({
title: "贪吃蛇",
template: "src/index.html"
})
]
}
html模板
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>
<%= htmlWebpackPlugin.options.title %>
</title>
<!-- <link src="xxx/xxx.css"> -->
</head>
<body>
</body>
</html>
package
{
"name": "tcs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.0",
"babel-loader": "^8.2.3",
"clean-webpack-plugin": "^4.0.0",
"core-js": "^3.19.1",
"html-webpack-plugin": "^5.5.0",
"postcss": "^8.3.11",
"postcss-loader": "^6.2.0",
"postcss-preset-env": "^6.7.0",
"ts-loader": "^9.2.6",
"typescript": "^4.4.4",
"webpack": "^5.64.0",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.4.0"
},
"devDependencies": {
"css-loader": "^6.5.1",
"less": "^4.1.2",
"less-loader": "^10.2.0",
"style-loader": "^3.3.1"
},
"scripts": {
"init": "tsc --init",
"build": "webpack",
"dev": "webpack-dev-server"
},
"keywords": [],
"author": "",
"license": "ISC"
}