You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.7 KiB
JavaScript

2 years ago
// 引入一个包
const path = require("path");
// 引入HTML插件
const HTMLWebpackPlugin = require("html-webpack-plugin");
// 引入EsLint插件
const ESLintWebpackPlugin = require("eslint-webpack-plugin");
2 years ago
// webpack中的所有配置信息
module.exports = {
mode: "production",
2 years ago
// 指定入口文件
entry: "./src/main.ts",
2 years ago
// 指定打包文件所在目录
output: {
// 指定打包文件的目录
path: path.resolve(__dirname, "dist"),
// 打包后的文件名
filename: "bundle.js",
// 自动清空上一次打包的内容webpack4需使用扩展包clean-webpack-plugin插件来进行自动清空操作
clean: true,
2 years ago
// 不使用箭头函数的方式定义
environment: {
arrowFunction: false,
const: false
}
},
// 指定webpack打包时要使用的模块
module: {
// 指定要加载的规则
rules: [
{
// 指定规则生效的文件
test: /\.ts$/,
// 要使用的loader
use: [
// 配置babel
{
// 指定加载器
loader: "babel-loader",
// 设置babel
options: {
// 设置预定义环境
presets: [
[
// 指定环境的插件
"@babel/preset-env",
// 配置信息
{
// 要兼容的目标浏览器
targets: {
"chrome": "100",
"ie": "11"
},
// 指定corejs的版本
"corejs": "3",
// 使用corejs的方式usage表示按需加载
"useBuiltIns": "usage"
}
]
]
}
},
"ts-loader"
],
// 要排除的文件
exclude: /node_modules/
},
// 设置less文件的处理
{
test: /\.less$/,
use: [
"style-loader",
"css-loader",
// 引入postcss
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
[
"postcss-preset-env",
{
browsers: "last 2 versions"
}
]
]
}
}
},
"less-loader"
]
}
]
},
// 配置webpack插件
plugins: [
new HTMLWebpackPlugin({
template: "./public/index.html"
}),
new ESLintWebpackPlugin({
// 指定检查文件的根目录
context: path.resolve(__dirname, "src"),
2 years ago
})
],
// 设置引用模块
resolve: {
extensions: [".ts", ".js"]
}
};