nextjs-制作官网

nextjs官网

nextjs

导入本地字体

global.scss

@font-face {
  font-family: 'HYk2gj';
  src: url('/static/fonts/Montserrat-Light-6.otf');
  font-style: normal;
}

设置头部icon和标题

 <Head>
      <title>Konnect</title>
      <link rel="shortcut icon" href="/static/logo_s.png" type="image/x-icon" />
      <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"></meta>
    </Head>

设置移动端和pc端共存

使用了next相关的库next-useragent

一、可以使用屏幕的宽度来适配
window.innerWidth <= 1000
二、通过ua来适配
import React from 'react'
import {  withUserAgent } from 'next-useragent'
import DesktopContent from "../view/pc"
import MobileContent from "../view/h5"
import { setRem } from "../utils/rem"
// import VConsole from 'vconsole';

// const vConsole = new VConsole();

class IndexPage extends React.Component {

  static async getInitialProps(ctx) {
    return { useragent: ctx.ua.source }
  }
  componentDidMount() {
    const { ua } = this.props
    if(ua.isMobile) { 
      const { ua } = this.props
      const isMobile = ua.isMobile || ua.isIpad ||  ua.isAndroid || ua.isAndroid
      sessionStorage.setItem("isMobile", isMobile)
      setRem()
      window?.addEventListener('resize',setRem)
      return ()=>{
        window?.removeEventListener('resize',setRem)
      }
    }else {
      sessionStorage.removeItem("isMobile")
    }
  }

  render() {
    const { ua } = this.props
    const isMobile = ua.isMobile || ua.isIpad ||  ua.isAndroid || ua.isAndroid
    return (
      <>
        { isMobile ? (
        <MobileContent />
        ) : (
        <DesktopContent />
        ) }
      </>
    )
  }
}

export default withUserAgent(IndexPage)

移动端使用 postcss-px-to-viewport-8-plugin

next.config.js

module.exports = {
    plugins: {
      "postcss-px-to-viewport-8-plugin": {
        unitToConvert: "px",
        viewportWidth: 375,
        unitPrecision: 3,
        propList: ["*"],
        viewportUnit: "vw",
        fontViewportUnit: "vw",
        selectorBlackList: [],
        minPixelValue: 1,
        mediaQuery: false,
        replace: true,
        include: /\src\/h5Styles/,
        exclude: [
          /node_modules/
        ],
        landscape: false
      }
    },
  };

// module.exports = {
//   plugins: {
//     'postcss-pxtorem': {
//       rootValue: 100,
//       replace: true,
//       propList: ["*"],
//       exclude: /node_modules|^(\/src\/h5Styles\/)$|styles/i
//     }
//   }
// }

因为会作用于全局 pc的页面没有使用scss 使用style-js

next-seo 进行seo优化

https://www.npmjs.com/package/next-seo

import { NextSeo } from "next-seo";
 <NextSeo title="konnect" description="Build The Web3" />
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肥肥呀呀呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值