当前位置:   article > 正文

webpack 打包ts代码_webpack modules exports entry main.ts

webpack modules exports entry main.ts

 webpack.config.js

  1. const path=require("path")
  2. const HtmlWebpackPlugin=require("html-webpack-plugin")
  3. const { CleanWebpackPlugin } = require("clean-webpack-plugin")
  4. module.exports={
  5. entry : "./src/index.ts",
  6. output : {
  7. path : path.resolve(__dirname,"dist"),
  8. filename : "bundle.js",
  9. environment : {
  10. // arrowFunction : false,
  11. }
  12. },
  13. module : {
  14. rules : [
  15. {
  16. test : /\.ts$/,
  17. use : [
  18. {
  19. //指定加载器
  20. loader : "babel-loader",
  21. options : {
  22. presets : [
  23. [
  24. //浏览器环境配置插件
  25. "@babel/preset-env",
  26. //配置信息
  27. {
  28. //要兼容的目标浏览器
  29. targets : {
  30. chrome : "60",
  31. firefox : "50",
  32. ie : "9",
  33. safari : "10",
  34. edge : "17"
  35. },
  36. //让旧版浏览器运行corejs3.0内核
  37. "corejs" : "3",
  38. // //使用corejs方式,usage:按需加载
  39. "useBuiltIns" : "usage"
  40. }
  41. ]
  42. ]
  43. }
  44. },
  45. "ts-loader"
  46. ],
  47. exclude : /node_modules/
  48. }
  49. ]
  50. },
  51. plugins : [
  52. //删除上一次编译的所有文件,重新编译
  53. new CleanWebpackPlugin(),
  54. //自动生成html文件
  55. new HtmlWebpackPlugin({
  56. //title : "自定义"
  57. template : "./src/index.html" //指定模板
  58. }),
  59. ], mode : "production",
  60. resolve : {
  61. //让文件识别引入的ts模块,js模块
  62. extensions : [".ts",".js"]
  63. }
  64. }

package.json

  1. {
  2. "name": "ts1",
  3. "version": "1.0.0",
  4. "description": "",
  5. "main": "index.js",
  6. "scripts": {
  7. "test": "echo \"Error: no test specified\" && exit 1",
  8. "build": "webpack",
  9. "serve": "webpack serve --open"
  10. },
  11. "keywords": [],
  12. "author": "",
  13. "license": "ISC",
  14. "devDependencies": {
  15. "@babel/core": "^7.16.0",
  16. "@babel/preset-env": "^7.16.4",
  17. "babel-loader": "^8.2.3",
  18. "core-js": "^3.19.1",
  19. "ts-loader": "^9.2.6",
  20. "typescript": "^4.5.2",
  21. "webpack": "^5.64.2",
  22. "webpack-cli": "^4.9.1",
  23. "webpack-dev-server": "^4.5.0"
  24. },
  25. "dependencies": {
  26. "D": "^1.0.0",
  27. "clean-webpack-plugin": "^4.0.0",
  28. "html-webpack-plugin": "^5.5.0"
  29. }
  30. }

tsconfig.json

  1. {
  2. "compilerOptions": {
  3. "module": "es2015",
  4. "target": "es2015",
  5. "strict" : true
  6. }
  7. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/1002575
推荐阅读
相关标签
  

闽ICP备14008679号