javascript - Angular 6 - Less CSS' import is not working anymore - Stack Overflow

I wanted to re-use some structure from an Angular 5 project which uses Less. In this old project I coul

I wanted to re-use some structure from an Angular 5 project which uses Less. In this old project I could simply load .less files using this line from within a ponent:

@import '~app/shared/less/bootstrap';

This would load:

/my-app/src/app/shared/less/bootstrap.less

Now I have a blank Angular 6 project, which is also configured to use Less as a preprocessor:

ng new my-app --routing --style less

Extract from angular.json:

"my-app": {
  "prefix": "app",
  "schematics": {
    "@schematics/angular:ponent": {
      "styleext": "less"
    }
  },
  "architect": {
    "build": {
      "options": {
        "styles": [
          "src/styles.less",
          "app/shared/less/styles.less"

However the line

@import '~app/shared/less/bootstrap';

… piles with an error:

Failed to pile.
./src/app/shared/ponent/someponent.less
Module build failed:
@import '~app/shared/less/bootstrap';
^
'~app/shared/less/bootstrap' wasn't found.

I also tried:

@import '.app/shared/less/bootstrap';
@import '.src/app/shared/less/bootstrap';
@import '~app/shared/less/bootstrap.less';

… without any luck.

Did I forget to configue something?

I wanted to re-use some structure from an Angular 5 project which uses Less. In this old project I could simply load .less files using this line from within a ponent:

@import '~app/shared/less/bootstrap';

This would load:

/my-app/src/app/shared/less/bootstrap.less

Now I have a blank Angular 6 project, which is also configured to use Less as a preprocessor:

ng new my-app --routing --style less

Extract from angular.json:

"my-app": {
  "prefix": "app",
  "schematics": {
    "@schematics/angular:ponent": {
      "styleext": "less"
    }
  },
  "architect": {
    "build": {
      "options": {
        "styles": [
          "src/styles.less",
          "app/shared/less/styles.less"

However the line

@import '~app/shared/less/bootstrap';

… piles with an error:

Failed to pile.
./src/app/shared/ponent/some.ponent.less
Module build failed:
@import '~app/shared/less/bootstrap';
^
'~app/shared/less/bootstrap' wasn't found.

I also tried:

@import '.app/shared/less/bootstrap';
@import '.src/app/shared/less/bootstrap';
@import '~app/shared/less/bootstrap.less';

… without any luck.

Did I forget to configue something?

Share Improve this question edited Jun 26, 2018 at 11:40 lampshade asked Jun 26, 2018 at 11:26 lampshadelampshade 2,8167 gold badges46 silver badges89 bronze badges 6
  • try to add extantion to you imports(like .js, .css) @import '.app/shared/less/bootstrap.less'; – לבני מלכה Commented Jun 26, 2018 at 11:49
  • Thanks for your suggestion, @לבנימלכה. As mentioned in the quesiton - I already tried it without any luck, unfortunately. – lampshade Commented Jun 26, 2018 at 11:57
  • see my answer please – לבני מלכה Commented Jun 26, 2018 at 11:57
  • use / before app : @import './app/shared/less/bootstrap.less' – לבני מלכה Commented Jun 26, 2018 at 12:02
  • @לבנימלכה Your idea was close. I got it working using the fully qualified path @import './src/app/ - including ./ and src. Thanks. Would you add this to your answer? – lampshade Commented Jun 26, 2018 at 12:14
 |  Show 1 more ment

1 Answer 1

Reset to default 6

In angular 6 you have to import all files to main(in your case src/styles.less) css file :

In angular.json put ONLY:

  "styles": [
          "src/styles.less"
]

In styles.less (import all files you want with / before app):

@import './app/shared/less/bootstrap.less';

See my answer to css here:Angular 6 load css folders in angular.json

To your edit ./src/app..:

@import './src/app/...'

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744078558a4554856.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
能,也可根据模型 hook 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>