react: nextJs koa project basic structure
1、init nextJs project
npm init
npm install react react-dom next
config script in package.json
"dev": "next" "start": "next start" "build": "next build"
npm run dev
result: 404 page not found
2、index.js entry file
export default () => <span>hello react next<span>
result: hello react next
3、koa server
npm install koa koa-router
const Koa = require('koa');
const next = require('next');
const dev = process.env.NODE_ENV !== "production";
//创建next app处于开发状态
const app = next({ dev });
const handle = app.getRequestHandler();
//页面加载编译完成后在处理请求
app.prepare().then(() => {
const server = new Koa();
//中间件的使用
server.use(async (context, next) => {
//request,response,req,res;await next() 执行下一个中间件
await handle(context.req, context.res);
context.respond = false;
});
server.listen(3000, () => {
console.log("koa server listening on 3000")
})
})
update script
"dev": "node server.js"
4、next with antd and css
npm install antd @zeit/next-css babel-plugin-import
for css config next.config.js
const withCss = require('@zeit/next-css');
if (typeof require !== 'undefined') {
require.extensions['.css'] = file => {}
}
module.exports = withCss({})
for antd config .babelrc
{
"presets": ["next/babel"],
"plugins": [
[
"import",
{
"libraryName": "antd",
"style": "css"
}
]
]
}
test valid
app.js
import App from "next/app"; import "antd/dist/antd.css"; export default App
update index.js
import { Button } from "antd";
export default () => <Button type="primary">hello world</Button>
react: nextJs koa project basic structure的更多相关文章
- China Brain Project: Basic Neuroscience, Brain Diseases, and Brain-Inspired Computing
日前,中国科学院神经科学研究所.中国科学院脑科学与智能技术卓越创新中心.香港科技大学生命科学部和分子神经科学国家重点实验室.中国科技大学自动化研究所在 Cell 上联合发表了一篇概述论文<Chi ...
- [React Router v4] Create Basic Routes with the React Router v4 BrowserRouter
React Router 4 has several routers built in for different purposes. The primary one you will use for ...
- 前端react+redux+koa写的博客推荐
React-Node搭建的博客 曾经用的php+mysql+js写的博客,现在看来已经很low了,所以用目前最火的react+koa框架重构一下.先上地址吧:目前线上版本http://www.liuw ...
- React与Koa一起打造一个功能丰富的全栈个人博客(业务篇)
前言 豆哥的个人博客又改版了,本版主要技术栈是前台用的React,后台用的Koa.博客改版的初衷是自己可以练练React(公司的项目部分要用React,我也没法啊,再说早晚得学).本文主要介绍博客的业 ...
- Vue: webpack js basic structure
vue webpack所用基础包: nom install vue vue-loader webpack webpack-cli webpack-dev-server vue-template-com ...
- React与Koa一起打造一个仿稀土掘金全栈个人博客(技术篇)
本篇文章将分为前台角度与后台角度来分析我是怎么开发的.前台角度主要资源 react.js ant Design for-editor axios craco-less immutable react- ...
- 1.Basic Structure
配置: rsyslogd 配置通过rsyslog.conf file,典型的在/etc下.默认的, rsyslogd 读取/etc/rsyslog.conf 文件,这个可以通过命令行选项改变 注意 配 ...
- Project Management Process
Project Management ProcessDescription .............................................................. ...
- react问题解决的一些方法
原文链接: https://segmentfault.com/a/1190000007811296?utm_source=tuicool&utm_medium=referral 初学者对Rea ...
随机推荐
- Python Seaborn综合指南,成为数据可视化专家
概述 Seaborn是Python流行的数据可视化库 Seaborn结合了美学和技术,这是数据科学项目中的两个关键要素 了解其Seaborn作原理以及使用它生成的不同的图表 介绍 一个精心设计的可视化 ...
- linux 中的页缓存和文件 IO
本文所述是针对 linux 引入了虚拟内存管理机制以后所涉及的知识点.linux 中页缓存的本质就是对于磁盘中的部分数据在内存中保留一定的副本,使得应用程序能够快速的读取到磁盘中相应的数据,并实现不同 ...
- spring ioc源码简析
ClassPathXmlApplicationContext 首先我们先从平时启动spring常用的ClassPathXmlApplicationContext开始解析 ApplicationCont ...
- SimpleITK 和 Nibabel 读取医学图像 nii 数据(2D显示)
SimpleITK 和 Nibabel 区别在于:(nii图像可以看成2维,也可以看成三维) SimpleITK读取数据是(X,Y,Z)显示,Nibabel读取图像是(Z,Y,X)显示,也就是Niba ...
- JS 剑指Offer(二)二维数组中的查找
04.在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序. 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. var ...
- 利用data文件恢复MySQL数据库
背景:测试服务器 MySQL 数据库不知何种原因宕机,且无法启动,而原先的数据库并没有备份,重新搭建一个新服务器把原data 复制出来 进行恢复 1 尽量把原data复制出来(一个都不要少以防意外 其 ...
- FCOS : 找到诀窍了,anchor-free的one-stage目标检测算法也可以很准 | ICCV 2019
论文提出anchor-free和proposal-free的one-stage的目标检测算法FCOS,不再需要anchor相关的的超参数,在目前流行的逐像素(per-pixel)预测方法上进行目标检测 ...
- B - Charlie's Change
Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie drives a lot and so he often buys coffe ...
- LeetCode | 169. 多数元素
给定一个大小为 n 的数组,找到其中的多数元素.多数元素是指在数组中出现次数大于 ⌊ n/2 ⌋ 的元素. 你可以假设数组是非空的,并且给定的数组总是存在多数元素. 示例 1: 输入: [3,2,3] ...
- 查找 mysql 配置文件 my.cnf
$ locate my.cnf 看看你的linux上有多少个my.cnf,一般都配置为/etc/my.cnf