当前位置:网站首页>1, 基本配置
1, 基本配置
2022-06-30 09:32:00 【山川pro】
一、上手 webpack
npm init -y
npm install webpack webpack-cli --save-dev
二、启动本地 server
- 安装插件
npm install --save-dev webpack-dev-server
- 配置
- 在
package.json
中配置 script 指令
"scripts": {
"dev": "webpack-dev-server --config ./webpack/webpack-dev-config.js --mode development --open",
},
相应的webpack-dev-config.js
文件代码
const path = require('path')
const { merge } = require('webpack-merge') //把基本webpack配置和开发(生产)环境的配置合并
const webpackConfigBase = require('./webpack-base-config')
function resolve(relatedPath) {
return path.join(__dirname, relatedPath)
}
const webpackConfigDev = {
mode: "development",
optimization: {
splitChunks: {
chunks: "all", //all(全部模块)
},
},
devServer: {
static: {
directory: resolve('../src'),
},
historyApiFallback: false,
open: true,
compress: true,
host: '127.0.0.1',
port: 9096,
hot: true, //启动热更新
},
devtool: 'inline-source-map'
}
module.exports = merge(webpackConfigBase, webpackConfigDev)
三、使用 babel 编译 react
- 下载相关插件
npm i babel-loader --save-dev //^8.2.5
npm install @babel/core --save-dev //^7.18.0
npm i @babel/preset-react --save-dev //^7.17.12
npm i @babel/preset-env --save-dev //^7.18.0
npm i @babel/plugin-transform-runtime
- 配置
.babelrc
文件
{
"presets": [
[
"@babel/preset-react",
{
"runtime": "automatic"
}
],
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"targets": {
"chrome": "49",
"ie": "11"
},
"corejs": 2
}
]
],
"plugins": ["@babel/plugin-transform-runtime"]
}
- 修改 webpack 配置文件
module: {
rules: [
...
{
test: /\.js[x]?$/,
include: [paths.src],
exclude: /node_modules/,
use: [
'babel-loader?cacheDirectory', // 开启缓存
],
},
...
]
}
四、下载 react 相关包
npm install --save react react-dom
边栏推荐
- Startup of MySQL green edition in Windows system
- ES6 learning path (III) deconstruction assignment
- Metasploit practice - SSH brute force cracking process
- 目标检测yolov5开源项目调试
- JVM tuning tool introduction and constant pool explanation
- Solution to the sixth training competition of 2020 provincial competition
- List set export excel table
- 4. use ibinder interface flexibly for short-range communication
- Niuke rearrangement rule taking method
- Row column (vertical and horizontal table) conversion of SQL
猜你喜欢
Talk about the kotlin cooperation process and the difference between job and supervisorjob
Express - static resource request
Distributed ID
Flutter 0001, environment configuration
Talking about kotlin process exception handling mechanism
About the smart platform solution for business hall Terminal Desktop System
4. use ibinder interface flexibly for short-range communication
Small program learning path 1 - getting to know small programs
Concatapter tutorial
小程序手持弹幕的原理及实现(uni-app)
随机推荐
Reading notes of "Introduction to deep learning: pytoch"
Differences between the notify(), notifyall(), notifydatasetchanged(), notifydatasetinvalidated() methods in the adapter
Mysq database remote connection error, remote connection is not allowed
About the smart platform solution for business hall Terminal Desktop System
[shutter] solve failed assertion: line 5142 POS 12: '_ debugLocked‘: is not true.
ES6 learning path (II) let & const
Application of hongruan face recognition
Baidu map JS browsing terminal
JVM family
DataTableToModelList实体类
AutoUpdater. Net client custom update file
【新书推荐】Cleaning Data for Effective Data Science
I once met a girl whom I most wanted to take care of all my life. Later... No later
Self service terminal handwritten Chinese character recognition input method library tjfink introduction
Abstract factory pattern
List set export excel table
Cftpconnection:: getfile() download FTP server files and related parameter descriptions
Ocx control can be called by IE on some computers, but can not be called by IE on some computers
Framework program of browser self-service terminal based on IE kernel
Niuke IOI weekly competition 20 popularization group (problem solving)