当前位置:网站首页>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
边栏推荐
- Deep Learning with Pytorch- A 60 Minute Blitz
- Idea setting automatic package Guide
- Bluetooth BT RF test (forwarding)
- 8.8 heap insertion and deletion
- Using OpenCV Net for image restoration
- Tablet PC based ink handwriting recognition input method
- Talk about writing
- Microsoft. Bcl. Async usage summary -- in Net framework 4.5 project Net framework version 4.5 and above can use async/await asynchronous feature in C 5
- Distributed things
- About the smart platform solution for business hall Terminal Desktop System
猜你喜欢
Distributed ID
Concatapter tutorial
[wechat applet] realize applet pull-down refresh and pull-up loading
Talk about how the kotlin process started?
Talk about the job experience of kotlin cooperation process
仿照微信Oauth2.0接入方案
Framework program of browser self-service terminal based on IE kernel
Talk about how the kotlin collaboration process establishes structured concurrency
Linear-gradient()
Terminal -- Zsh of terminal three swordsmen
随机推荐
Using OpenCV Net for image restoration
Why must redis exist in distributed systems?
Splice and slice functions of JS
Differences between the notify(), notifyall(), notifydatasetchanged(), notifydatasetinvalidated() methods in the adapter
JVM family
What kind of experience is it to develop a "grandson" who will call himself "Grandpa"?
Set, map and modularity
Wechat development tool (applet)
9.JNI_ Necessary optimization design
Self service terminal handwritten Chinese character recognition input method library tjfink introduction
8.8 heap insertion and deletion
Installation, use and explanation of vulnerability scanning tool OpenVAS
Bottomsheetbehavior principle of realizing the home page effect of Gaode map
Tclistener server and tcpclient client
八大排序(一)
Couldn't load this key (openssh ssh-2 private key (old PEM format))
JVM tuning tool introduction and constant pool explanation
The elegant combination of walle and Jianbao
Deep Learning with Pytorch- A 60 Minute Blitz
Cronexpression expression explanation and cases