No Result
View All Result
CloudReports
  • Home
  • Linux
  • Web development
  • Javascript
  • SQL
  • Ant Design tutorial
  • QR Code Scanner
  • Home
  • Linux
  • Web development
  • Javascript
  • SQL
  • Ant Design tutorial
  • QR Code Scanner
No Result
View All Result
CloudReports
No Result
View All Result
Home Javascript

Next.js + Ant Design with less – Advanced Nextjs and Ant design scaffolding

by Alicja Zelazko
July 26, 2019
in Javascript, React
Reading Time: 3 mins read
0
0
SHARES
2.9k
VIEWS
Share on FacebookShare on Twitter

Contents

  • 1 Foreword
      • 1.0.1 Next.js Beginner’s Guide Series Address
  • 2 Next.js scaffolding advanced series
  • 3 Some problems with ant-design
  • 4 Another water, this series I want to step by step from the scaffolding step by step to improve so that everyone is more convenient to use, increase scalability.
Rate this post

Foreword

After the last introduction, I feel that I still have a lot of feelings. I always feel that this scaffolding is still not perfect, and there are places that can be improved. Therefore, in order to be convenient with people, it is convenient to continue to write a few articles~?, but since the previous one is called the entry series. This is called advanced ~

Check out these tutorials about Next.js

Convert HTML template into NextJs app

Create custom self-api Next.js api server

NextJs + KoaJs Create custom NextJs server with KoaJs

[Tutorial] Create react based server side rendering app with NextJS

NextJs Data fetching – Combine Server Side and Client Side fetching

Cloudreports – Next.js tutorials

Next.js Beginner’s Guide Series Address

Next.js scaffolding advanced series

  • Perfect fit ant-design
  • Encapsulate fetch & add middleware
  • Deployment online

Some problems with ant-design

Because the Next.js version is constantly being updated, especially after upgrading to 7, many plug-ins are upgraded, so if you are using a version below Next.js7, you should be cautious about the upgrade. Because the official said that 7 speed is much faster, with the principle of puncturing my priority, I started the road of upgrading, and even the most problems encountered are the problems with ant-design. The main problems appear in three aspects. :

Various plugins upgrades

// Next.js 6 version
"dependencies": {
  "@zeit/next-less": "^0.3.0",
  "babel-plugin-import": "^1.8.0",
  ...
},
"devDependencies": {
  "babel-plugin-transform-decorators-legacy": "^1.3.5",
  ...
}

// Next.js 7 version
"dependencies": {
  "@zeit/next-less": "^1.0.1",
  "babel-plugin-import": "^1.9.0",
  ...
},
"devDependencies": {
  "@babel/plugin-proposal-decorators": "^7.1.0",
  ...
}

The first is that the core file of next-less needs to be upgraded, and then the plugin for babel and ant is switched. Specifically can be seen in the code.

ADVERTISEMENT

Directory structure changes lead to static CSS file import path problem

First of all, the previous use of Next.js 6, all css files will be packaged into style.css storage path is /.next/static/style.css. After Next.js 7, it should be webpack optimized CSS compilation. After compiling, the folder structure is as follows:

It can be seen that not only the structure has changed, but also the name has changed. It should be the built-in webpack for optimization of css. In short, now, with the v6 version of the code, our browser will report a mistake, as shown below:

Solution: Remove the link tag of the Head header of _app.js and change it to the import style file at the top of _app.js.

The problem of ant-design’s custom file being overwritten after packagingimport ‘../asserts/styles.less’;

Finally, the most headaches, after the above changes, you will find in the development environment, OK, the upgrade is successful, but you try to package it, after packaging, your custom-css style will be ant-design original style The coverage, that is, your custom-css file does not take effect.

【Solution】:

If you accept the ant-design style, use the properties of its own framework, it is completely OK, nothing to do.

  1. Change the package of ant-design by yourself.
  2. The previous article happened to be someone to leave a message for me. I used to know ignorance, maybe the second is the best solution, but until I found the most perfect solution below.
  3. The third one above is also used by me now. I have not found any problems at present. You can use it with confidence~
// next.config.js
...
// Where your antd-custom.less file lives
  const themeVariables = lessToJS(
    fs.readFileSync(
      path.resolve(__dirname, './asserts/antd-custom.less'),
      'utf8',
    ),
  );
...
withLess({
    lessLoaderOptions: {
      javascriptEnabled: true,
      modifyVars: themeVariables, // Add modifyVars property
      localIdentName: '[local]___[hash:base64:5]',
    },
  ...
})

In addition to the official Demo I also helped with a simple update, and now the create-next-app

with-ant-design-less Demo is the version of my pr. to sum up

Another water, this series I want to step by step from the scaffolding step by step to improve so that everyone is more convenient to use, increase scalability.

Therefore, each article is only for one live two points, not a long story. Scaffolding Address: Next-Antd-Scaffold

like to give a Star, thank you very much~

Tags: Ant designNext.jsNext.js ant design
ShareTweetShare
Previous Post

How to properly cache on-demand records

Next Post

In-depth explanation about React Hooks – What is React Hooks?

Alicja Zelazko

Related Posts

Javascript

Configuring VS Code for Node/JavaScript Development

August 2, 2021
1.3k
Javascript

How does Nodejs solve the problem of high concurrency?

July 18, 2021
1.3k
React

Migrate from Hot Reload to Fast Refresh

December 16, 2020
1.5k
React

[React] React installation for Mac

December 16, 2020
325
Javascript

Npm module: a backdoor and ambush questions

December 16, 2020
316
Javascript

NPM: three packets contained malicious code

December 16, 2020
198
Next Post

In-depth explanation about React Hooks - What is React Hooks?

Discussion about this post

No Result
View All Result

Categories

  • Android (1)
  • Ant Design tutorial (7)
  • App/Game (2)
  • Javascript (16)
  • Layout and Routing (2)
  • Linux (9)
  • PC & LAPTOP (6)
  • PERSONAL FINANCES (1)
  • React (13)
  • SQL (2)
  • TECHNOLOGY & DIGITAL (7)
  • The Basics (5)
  • Web development (37)

Search

No Result
View All Result

Categories

  • Android (1)
  • Ant Design tutorial (7)
  • App/Game (2)
  • Javascript (16)
  • Layout and Routing (2)
  • Linux (9)
  • PC & LAPTOP (6)
  • PERSONAL FINANCES (1)
  • React (13)
  • SQL (2)
  • TECHNOLOGY & DIGITAL (7)
  • The Basics (5)
  • Web development (37)
No Result
View All Result
  • Home
  • Linux
  • Web development
  • Javascript
  • SQL
  • Ant Design tutorial
  • QR Code Scanner
Exit mobile version