question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to import less file globally with TSX file

See original GitHub issue

Prerequisites

  • Using yarn
  • Using node 10.x
  • Using an up-to-date master branch
  • Using latest version of devtools. See wiki for howto update
  • Link to stacktrace in a Gist (for bugs)
  • For issue in production release, devtools output of DEBUG_PROD=true yarn build && yarn start
  • Tried solutions mentioned in #400

Expected Behavior

Import ant.design styles globally and customize ui theme

I’m using ant.design UI

Current Behavior

Cannot import ant design less file globally

Possible Solution

Steps to Reproduce (for bugs)

1.Install related packages:

yarn add antd@3.26.15 less less-loader

2.less loader setting:

// webpack.config.renderer.prod.babel.js
        {
                test: /\.less$/,
                use: [
                    {
                        loader: MiniCssExtractPlugin.loader
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            modules: {
                                localIdentName:
                                    '[name]__[local]__[hash:base64:5]'
                            },
                            importLoaders: 1,
                            sourceMap: true
                        }
                    },
                    {
                        loader: 'less-loader',
                        options: {
                            sourceMap: true,
                            javascriptEnabled: true
                        }
                    }
                ]
            }
// webpack.config.renderer.dev.babel.js
        {
                test: /\.less$/,
                use: [
                    {
                        loader: 'style-loader'
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            modules: {
                                localIdentName:
                                    '[name]__[local]__[hash:base64:5]'
                            },
                            sourceMap: true,
                            importLoaders: 1
                        }
                    },
                    {
                        loader: 'less-loader',
                        options: {
                            sourceMap: true,
                            javascriptEnabled: true
                        }
                    }
                ]
            }

3.import antd theme from entrance file:

import 'antd/dist/antd.less';

4.Global import is not effective

Context

Your Environment

  • Node version :v10.16.3
  • Version or Branch used :v1.10
  • Operating System and version :win10
  • Link to your project :

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
steveetmcommented, Apr 20, 2020

Actually it is working for me, but if you use css modules, class names are replaced with hashed names and you must import the css file into a variable and assign class names that variable. This is why I said this could be undesired for a global import, as usually you don’t want this when less/scss/css is global. Either try

import styles from './yourLessStyle.less`;
[...]
return (
<div className={styles.classFromYourStyle}></div>
)

or remove modules: { localIdentName: '[name]__[local]__[hash:base64:5]' }, from your loader config.

0reactions
huangshuweicommented, Apr 20, 2020

@steveetm thx. it’s works when I remove css module config from less loader config

or remove modules: { localIdentName: ‘[name][local][hash:base64:5]’ }, from your loader config.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to require/import .less file in typescript file - Stack Overflow
If you just want to include the less file in your app, you can do import <path>/style.less . Webpack will then include (and...
Read more >
How to add Global CSS / LESS styles to React with webpack
Import the styles.less global stylesheet into your main React entry file (e.g. /src/index.js or /src/index.jsx ) with the following line.
Read more >
API - esbuild
To join a set of files together with esbuild, import them all into a single entry point file and bundle just that one...
Read more >
Styling - Remix
Shared stylesheet. The first approach is very simple. Put them all in a shared.css file included in app/root.tsx .
Read more >
Basic Features: Built-in CSS Support - Next.js
Next.js allows you to import CSS files from a JavaScript file. This is possible because Next.js extends the concept of import beyond JavaScript....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found