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.

does not support import remote css as less in less files

See original GitHub issue

Versions

  • dumi: 1.1.23
  • node: v14.15.4
  • npm: 6.14.11
  • OS: macOS Big Sur 11.2.3
  • Browser: Edge 91.0.864.67

Steps to reproduce

在组件的 less 样式文件里通过 @import 语法引入 web url 地址

@import (less) url('https://at.alicdn.com/t/font_2673961_hg2vb7cj7i.css');

.a {
  color: red;
}

What is Expected?

正确加载

What is actually happening?

启动时报错

image

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
PeachScriptcommented, Jul 16, 2021

@RunningCoderLee 理解了,Umi 自带的 less-loader 是锁到 5.0 的,背后是 3.x 的 Less.js,你使用的这个功能应该是 Less.js 4.0 出来的,所以要使用这个特性只能覆盖默认的 less-loader

1reaction
RunningCoderLeecommented, Jul 16, 2021

这个不算是用法问题吧,我单纯使用 webpack 的 demo 项目去验证这个场景是没有问题的

发现一个解决方案

.umirc.ts 中用 chainWebpack 更改 umi 引入的 less-loader 是可以解决这个问题的

import { defineConfig } from 'dumi'
import path from 'path'

export default defineConfig({
  chainWebpack(memo, { env, webpack, createCSSRule }) {
    // 替换 umi 自带的 less-loader 以解决 less 文件中 import web url 报错的问题
    memo.module
      .rule('less')
      .oneOf('css')
      .use(
        path.resolve(
          __dirname,
          'node_modules/@umijs/bundler-webpack/node_modules/@umijs/deps/compiled/less-loader/cjs.js',
        ),
      )
      .loader(require.resolve('less-loader'))
      .tap((options) => ({
        lessOptions: options,
      }))
  },
})

是不是引入的 loader 有问题?

顺带一提,在还没有明确问题根本原因前,能不能先不关闭 issue 并添加无效标签?

@PeachScript

Read more comments on GitHub >

github_iconTop Results From Across the Web

import .css file into .less file - Stack Overflow
If you want to import a CSS file, and don't want LESS to process it, just use the .css extension: @import "lib.css"; The...
Read more >
Importing remote urls broken with v3.0.1 #3188 - less/less.js
With less v2.7.3 (using webpack v3.1.0 and less-loader v4.1.0) I ... does not support import remote css as less in less files umijs/dumi#775....
Read more >
import - CSS: Cascading Style Sheets - MDN Web Docs
The @import CSS at-rule is used to import style rules from other valid stylesheets. An @import rule must be defined at the top...
Read more >
Css – import .css file into .less file - iTecNote
All imports are other .less files and all works as it should. My current issue is this: I want to import a .css...
Read more >
Style Sheets | IntelliJ IDEA Documentation - JetBrains
With IntelliJ IDEA, you can create new rulesets from existing declarations in CSS, SCSS, Sass, or Less files and even move entire rulesets ......
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