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

29 lines
1.5 KiB

4 years ago
  1. const path = require("path");
  2. module.exports = {
  3. entry: "./src/main.ts", // 入口ts文件,名字可以任取,但是一定要注意路径设置是否正确
  4. output: {
  5. filename: "./bundle.js" // 自动会产生dist目录,所以可以去掉dist/目录
  6. },
  7. mode: 'development', // 本书中,设置为开发模式
  8. devtool: "inline-source-map", // 如果要调试TypeScript源码,需要设置成这样
  9. resolve: {
  10. extensions: [".ts", ".js"] // 添加ts和js作为可解析的扩展
  11. },
  12. plugins: [
  13. ],
  14. module: {
  15. rules: [
  16. {
  17. test: /\.ts$/, // 正则表达式,如果是TypeScript源码的话
  18. loader: ["ts-loader"] // 则使用ts-loader来加载TypeScript源码,并进行转译
  19. }
  20. ]
  21. },
  22. devServer: { // 就是配置我们npm install webpack-dev-server --save-dev安装的那个服务器
  23. contentBase: path.join(__dirname, "./dist/"), // 设置url的根目录,如果不设置,则默认是指向项目根目录(和设置./效果一样)
  24. compress: true, //如果为 true ,开启虚拟服务器时,为你的代码进行压缩。加快开发流程和优化的作用
  25. host: '0.0.0.0', // 设置主机名,默认为"localhost"
  26. port: 3000, // 设置端口号,默认端口号为8080
  27. historyApiFallback: true, //让所有404错误的页面定位到index.html
  28. open: true //启动服务器时,自动打开浏览器,默认为false
  29. }
  30. };