-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webpack + React 单页实践#1:项目初始化 #7
Comments
S-T-D
changed the title
1. 使用 webpack 搭建 react 单页应用#1:项目初始化
1. webpack + React 单页实践#1:项目初始化
Mar 10, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
主要内容:
初始化项目
mkdir webpack-react-spa-template-project cd webpack-react-spa-template-project yarn init
安装
通常来说,建议将
webpack
作为项目依赖安装。基础配置
在项目根目录下新建
dist
目录,用于存放打包后的文件。进入
dist
目录,新建index.html
,内容如下。在项目根目录下新建
src
目录,用于存放业务代码。进入
src
目录,新建index.js
,内容如下。在项目根目录下新建
webpack.config.js
,内容如下。添加构建脚本到
package.json
,内容如下。可以在
webpack
命令后明确指定构建所使用的配置文件:webpack --config my-config.js
。如果不指定,则默认使用
webpack.config.js
。打开终端进入项目,运行构建命令。
可以看到构建成功了,此时,进入
dist
目录会发现新增了一个js
文件,也就是bundle.js
。查看运行效果:直接使用浏览器打开
dist
的index.html
,或者使用 serve 对dist
目录进行托管。代码地址
webpack-react-spa-template-project
The text was updated successfully, but these errors were encountered: