webpack4一个可用的搭配

已搭配功能详见 package.json
`
// webpack.config.js 文件

const path = require(‘path’);
const { CleanWebpackPlugin } = require(‘clean-webpack-plugin’)
const HtmlWebpackPlugin = require(‘html-webpack-plugin’)
module.exports = (env, argv) => {
const devMode = argv.mode !== ‘production’
return {
mode: ‘none’,
entry: [
“babel-polyfill”,
path.join(__dirname, ‘./src/index.js’)
],

    devServer: {
        contentBase: './dist', //将dist目录下的文件(index.html)作为可访问文件, 如果不写这个参数则默认与webpack.cofig.js的同级目录
        port: 8089 //端口号设为8080, 默认也是8080
    },
    plugins: [
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, './src/index.html'),
            title: 'hello sass',
            filename: 'index.html'
          })
    ],
    module: {
        rules: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            }
        ],
    },
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    },

}

}
`

"html-webpack-plugin": “^3.2.0” 这个的版本 搭配 webpack4 版本!!!
`
//package.json 文件

{
“name”: “node_hj_codes”,
“version”: “1.0.0”,
“main”: “webpack.config.js”,
“scripts”: {
“test”: “echo “Error: no test specified” && exit 1”,
“start”: “webpack-dev-server --mode development --module-bind js=babel-loader”,
“dev”: “webpack --mode development --module-bind js=babel-loader”,
“build”: “webpack --mode production --module-bind js=babel-loader”
},
“repository”: {
“type”: “git”,
“url”: “”
},
“keywords”: [],
“author”: “”,
“license”: “ISC”,
“description”: “”,
“devDependencies”: {
“@babel/core”: “^7.14.6”,
“@babel/plugin-transform-runtime”: “^7.14.5”,
“@babel/polyfill”: “^7.12.1”,
“@babel/preset-env”: “^7.14.7”,
“babel-loader”: “^8.2.2”,
“babel-plugin-transform-runtime”: “^6.23.0”,
“babel-polyfill”: “^6.26.0”,
“clean-webpack-plugin”: “^4.0.0-alpha.0”,
“css-loader”: “^5.2.6”,
“html-webpack-plugin”: “^3.2.0”,
“mini-css-extract-plugin”: “^1.6.0”,
“postcss-loader”: “^6.1.0”,
“style-loader”: “^2.0.0”,
“webpack”: “^4.46.0”,
“webpack-cli”: “^3.3.12”,
“webpack-dev-server”: “^3.11.2”
}
}

`
.babelrc 文件

{ "presets": [ [ "@babel/preset-env", { "useBuiltIns": "usage", "modules": false, "targets": { "browsers": "last 2 versions, not ie <= 9" } } ] ], "plugins": [ [ "@babel/plugin-transform-runtime", { "helpers": false } ] ] }

项目结构
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值