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 migrate cases that make use of @content and @import with @content and @forward

See original GitHub issue

I’m migrating a codebase from using @import to @use and @forward. Most of it is okay but I’m unsure what to do in a case where @import is used with @content.

Considering the following mixing that the only goal is to wrap styles in a class:

@mixin alternative-styles {
  .parent-class {
    @content;
  }
}

The mixin is then used with @import to wrap all those styles in a .parent-class:

@include alternative-styles {
  @import 'components';
}

I assumed replacing it with a @forward wouldn’t work but have it a try anyway in this way:

@include alternative-styles {
  @forward 'components';
}

This threw the following error:

Error: This at-rule is not allowed here.
   ╷
22 │   @forward 'components';
     │   ^^^^^^^^^^^^^^^^^^^^^
   ╵

Is there any way to achieve wrapping a bunch of styles in a class that supports the @use and @forward rules?

Thanks a lot in advance!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jathakcommented, Jul 7, 2021

You shouldn’t need to do a separate compilation.

Do components/buttons and components/text actually emit any CSS? If they do, it should be included by meta.load-css.

1reaction
csalmeidacommented, Jul 7, 2021

I have found that the sass-migration tool solves the issue this way:

@use 'sass:meta';
@use 'mixins';

@include mixins.alternative-styles {
  @include meta.load-css('components');
}

The components.scss files has multiple @forward statements to keep all component references in one place like this:

// components.scss
@forward 'components/buttons';
@forward 'components/text';

After the sass compiler runs it results in an empty block:

.parent-class {
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to migrate cases that make use of @content and @import ...
I found that the meta.load-css mixin actually does work after creating a separate prototype with the same structure: @use 'sass:meta'; @use ...
Read more >
Tableau Content Migration Tool Use Cases
Select the content you want to migrate from your source site. You can select entire projects, specific workbooks and data sources, and user...
Read more >
Here's How to Migrate Data to Content In Salesforce - Altvia
Attachments & Document Files: Start by doing a full Export including all files from within SF. This will get you all the attachments,...
Read more >
Migrate Content - Box Support
Potential migration methods · Drag and Drop Files · Upload Folders · FTP · Box Shuttle – content migration at scale.
Read more >
Import Your Team's Data Into G Suite - Zapier
Just open the G Suite Admin page and select Migration, or go directly to admin.google.com/AdminHome#Migration. Select what you'd like to import ...
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