1. // webpack.config.js
    2. const path = require("path");
    3. const webpack = require("webpack");
    4. const HtmlWebpackPlugin = require("html-webpack-plugin");
    5. const { CleanWebpackPlugin } = require("clean-webpack-plugin");
    6. module.exports = {
    7. mode: "development", // production development
    8. // development devtool cheap-module-eval-source-map
    9. // production devtool cheap-module-source-map
    10. devtool: "cheap-module-eval-source-map",
    11. entry: {
    12. sendlog: "./src/index.js",
    13. },
    14. output: {
    15. // publicPath: "https://j.weizan.cn",
    16. filename: "[name].js",
    17. path: path.resolve(__dirname, "dist"),
    18. },
    19. devServer: {
    20. contentBase: "./dist",
    21. open: true,
    22. hot: true,
    23. hotOnly: true,
    24. },
    25. module: {
    26. rules: [
    27. {
    28. test: /\.js$/,
    29. exclude: /node_modules/,
    30. loader: "babel-loader",
    31. options: {
    32. // 业务代码(存在全局污染)
    33. presets: [
    34. [
    35. "@babel/preset-env",
    36. {
    37. targets: {
    38. chrome: "67",
    39. },
    40. useBuiltIns: "usage",
    41. },
    42. ],
    43. ],
    44. // 库代码(类似于闭包形式)
    45. plugins: [
    46. [
    47. "@babel/plugin-transform-runtime",
    48. {
    49. corejs: 2,
    50. helpers: true,
    51. regenerator: true,
    52. useESModules: false,
    53. },
    54. ],
    55. ],
    56. },
    57. },
    58. ],
    59. },
    60. plugins: [
    61. new HtmlWebpackPlugin({
    62. template: "src/index.html",
    63. }),
    64. new CleanWebpackPlugin(),
    65. new webpack.HotModuleReplacementPlugin(),
    66. ],
    67. };
    1. {
    2. "name": "log",
    3. "version": "1.0.0",
    4. "description": "",
    5. "private": true,
    6. "directories": {
    7. "lib": "lib"
    8. },
    9. "scripts": {
    10. "serve": "webpack-dev-server",
    11. "build": "webpack"
    12. },
    13. "keywords": [],
    14. "author": "",
    15. "license": "ISC",
    16. "devDependencies": {
    17. "@babel/core": "^7.10.3",
    18. "@babel/plugin-transform-runtime": "^7.10.3",
    19. "@babel/preset-env": "^7.10.3",
    20. "babel-loader": "^8.1.0",
    21. "clean-webpack-plugin": "^3.0.0",
    22. "html-webpack-plugin": "^4.3.0",
    23. "webpack": "^4.43.0",
    24. "webpack-cli": "^3.3.12",
    25. "webpack-dev-server": "^3.11.0"
    26. },
    27. "dependencies": {
    28. "@babel/polyfill": "^7.10.1",
    29. "@babel/runtime": "^7.10.3",
    30. "@babel/runtime-corejs2": "^7.10.3",
    31. "axios": "^0.19.2",
    32. "protobufjs": "^6.9.0"
    33. }
    34. }
    1. import "@babel/polyfill";