当前位置: 首页 > news >正文

webpack打包基本配置

需要的文件

在这里插入图片描述

具体代码

webpack.config.js

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}},module: {rules: [{test: /\.ts$/,use: [{loader: 'babel-loader',options: {"presets": [["@babel/preset-env",{"targets": {"browsers": ["ie 11"]},"corejs": 3, // 注意这里应该是数字 3,而不是字符串 "3""useBuiltIns": "usage" // 注意大小写,是 "useBuiltIns" 而不是 "useBuiltins"}]]}},'ts-loader',],exclude: /node_modules/,}]},plugins: [new CleanWebpackPlugin(),new HTMLWebpackPlugin({template: "./src/index.html"})],resolve: {extensions: ['.ts', '.tsx', '.js']}
}

tsconfig.json

{"compilerOptions": {"target": "es2015","module": "es2015","strict": true,}
}

package.json

{"name": "part3","version": "1.0.0","main": "index.js","scripts": {"test": "echo \"Error: no test specified\" && exit 1","build": "webpack","start": "webpack serve --open"},"keywords": [],"author": "","license": "ISC","description": "","devDependencies": {"@babel/core": "^7.27.3","@babel/preset-env": "^7.27.2","babel-loader": "^10.0.0","clean-webpack-plugin": "^4.0.0","core-js": "^3.42.0","html-webpack-plugin": "^5.6.3","ts-loader": "^9.5.2","typescript": "^5.8.3","webpack": "^5.99.9","webpack-cli": "^6.0.1","webpack-dev-server": "^5.2.1"}
}

index.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<div id="app">This is a template
</div>
</body>
</html>

index.ts

import {hi} from './m1'function sum(a:number, b:number):number {return a + b;
}const  obj={name:"孙悟空",age:33}
console.log(obj)obj.age=18;
console.log(obj)console.log(sum(123,456))
console.log(sum(123,2))
console.log(hi)console.log(Promise)

m1.ts

export const hi='你好啊'

相关文章:

  • GUI 编程——python
  • 干货|VR全景是什么?
  • 同源“平滑思想”的问题解法:正则化与拉普拉斯平滑
  • hi3516cv610分配多个 vb pool及查看vb信息
  • Linux的SHELL脚本基础
  • 在qt中使用c++实现与Twincat3 PLC变量通信
  • Kubernetes Dashboard 安装部署、访问与管理实战实验
  • VScode单双引号、分号格式
  • 【深度学习-pytorch篇】4. 正则化方法(Regularization Techniques)
  • ParakeetTDT0.6BV2,语音识别ASR,极速转录, 高精度英文转录,标点支持(附整合包)
  • 常用算法模板函数(Python)
  • 用Python玩转人工智能——手搓图像分类模型
  • 【PhysUnits】13 改进减法(sub.rs)
  • 【加密算法】
  • 从“被动养老”到“主动健康管理”:平台如何重构代际关系?
  • Odoo 条码功能全面深度解析(VIP15万字版)
  • LiveNVR :实现非国标流转国标流的全方位解决方案
  • 勾股数的性质和应用
  • 接地气的方式认识JVM(一)
  • 通过teamcity cloud创建你的一个build
  • 企业网站建设性能分析/站长工具端口扫描
  • 米拓做的网站如何改代码/百度一下百度下载
  • php动态网站开发实训8/关键词优化排名软件案例
  • 自己做网站系统教程/广州百度快速优化排名
  • 学做网站前景/网络营销专业大学排名
  • b2b网站盈利模式/外贸平台自建站