javascript
// webpack.config.js
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
module.exports = {
mode: 'development', // production development
// development devtool cheap-module-eval-source-map
// production devtool cheap-module-source-map
devtool: 'cheap-module-eval-source-map',
entry: {
sendlog: './src/index.js',
},
output: {
// publicPath: "https://j.weizan.cn",
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
devServer: {
contentBase: './dist',
open: true,
hot: true,
hotOnly: true,
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
// 业务代码(存在全局污染)
presets: [
[
'@babel/preset-env',
{
targets: {
chrome: '67',
},
useBuiltIns: 'usage',
},
],
],
// 库代码(类似于闭包形式)
plugins: [
[
'@babel/plugin-transform-runtime',
{
corejs: 2,
helpers: true,
regenerator: true,
useESModules: false,
},
],
],
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.html',
}),
new CleanWebpackPlugin(),
new webpack.HotModuleReplacementPlugin(),
],
}
json
{
"name": "log",
"version": "1.0.0",
"description": "",
"private": true,
"directories": {
"lib": "lib"
},
"scripts": {
"serve": "webpack-dev-server",
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.10.3",
"@babel/plugin-transform-runtime": "^7.10.3",
"@babel/preset-env": "^7.10.3",
"babel-loader": "^8.1.0",
"clean-webpack-plugin": "^3.0.0",
"html-webpack-plugin": "^4.3.0",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"@babel/polyfill": "^7.10.1",
"@babel/runtime": "^7.10.3",
"@babel/runtime-corejs2": "^7.10.3",
"axios": "^0.19.2",
"protobufjs": "^6.9.0"
}
}
javascript
import '@babel/polyfill'