当前位置:网站首页>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
边栏推荐
- 银河麒麟server-V10配置镜像源
- Clickhouse installation (quick start)
- Express の Hello World
- Research on lg1403 divisor
- Electron, which can wrap web page programs into desktop applications
- ES6 learning path (III) deconstruction assignment
- What is the difference between ZigBee, Bluetooth and WiFi (copy and reprint)
- Interviewer: do you understand the principle of recyclerview layout animation?
- 8.8 heap insertion and deletion
- Deep Learning with Pytorch-Train A Classifier
猜你喜欢

仿照微信Oauth2.0接入方案

Acquisition de 100% des actions de Guilin latex par Guilin Robust Medical pour combler le vide de la gamme de produits Latex

Metasploit practice - SSH brute force cracking process

Distributed things

5. Messager framework and imessager interface

Wechat development tool (applet)

Bottomsheetbehavior principle of realizing the home page effect of Gaode map

Guilin robust medical acquired 100% equity of Guilin Latex to fill the blank of latex product line

MySQL explain

Pit encountered by fastjason
随机推荐
Deep Learning with Pytorch - autograd
Demo of guavacache
Net framework system requirements
ES6 learning path (II) let & const
Tclistener server and tcpclient client
8.8 heap insertion and deletion
Design of mfc+mysql document data management system based on VS2010
Distributed things
Using appbarlayout to realize secondary ceiling function
7. know JNI and NDK
八大排序(二)
Bottomsheetbehavior principle of realizing the home page effect of Gaode map
Dart asynchronous task
Concatapter tutorial
Coredata acquisition in swift sorting, ascending, descending
DDD interview
(zero) most complete JVM knowledge points
Explanation on the use of password profiteering cracking tool Hydra
OCX child thread cannot trigger event event (forward)
Differences between the notify(), notifyall(), notifydatasetchanged(), notifydatasetinvalidated() methods in the adapter