La la la la la do not want to put on a very big webpack gave up the idea of inquiry, in fact webpack particularly approachable, is a tool
today saw a super beautiful project
You can see a variety of mouth red numbers, full screen pink, yapping Wow, Mimi da
This is an open source project, the project addresses are: https://github.com/Ovilia/lipstick
open project, look package.json file, I was surprised to find no commands to run
hindsight issue
uh uh uh, I need to install nginx and tomcat wow ~
I'm a front-end engineer it ~Humph~
Direct local projects run wow look at
cross-domain problems identified
now I most want to do is add a command to run the project, and a reverse proxy to avoid cross-domain issue
we take a look at webpack documents
we found webpack- dev-server will be able to solve our pain points, it can provide a web server function to us
then we will use it in accordance with its demands
first step is to install webpack-dev-server
root directory create webpack.config.js
//webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
mode: 'development',
entry: {
app: './src/index.js',
print: './src/print.js'
},
devtool: 'inline-source-map',
devServer: {
contentBase: './dist'
},
plugins: [
// new CleanWebpackPlugin(['dist/*']) for < v2 versions of CleanWebpackPlugin
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'Development'
})
],
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
}
};
这告诉webpack-dev-server我们从dist目录中提供文件localhost:8080
修改package.json
我们先来运行项目看看
说是没有安装webpack
哪里报错解决哪里
现在安装webpack
接下来我们来修改项目的目录结构
修改dist/index.html
接下来修改
现在,让我们再次运行构建,而不是使用我们的新配置文件:
npx webpack --config webpack.config.js
最后我们使用npm start进行运行
项目运行为
好啦啦啦啦啦,收工~~~我也是棒棒哒,加油哇