Skip to content

Issue 427 #824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 6, 2021
Merged

Issue 427 #824

merged 4 commits into from
Sep 6, 2021

Conversation

alexander-akait
Copy link
Member

@alexander-akait alexander-akait commented Sep 6, 2021

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

fixes #427

Breaking Changes

No

Additional Info

Two simple scenrious:

  1. loaded default (light) and async loading additional (dark)
  2. async loading light and dark

There could be many more scenarios here - you can use var() and load only files with with variables, you can use multiple entries and more.

The main idea is using resourceQuery and import(/* webpackChunkName: "dark" */ "./style.scss?dark") so you can run multiple times sass-loader/etc

@codecov
Copy link

codecov bot commented Sep 6, 2021

Codecov Report

Merging #824 (bae3ce7) into master (704bea9) will increase coverage by 0.13%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #824      +/-   ##
==========================================
+ Coverage   92.68%   92.82%   +0.13%     
==========================================
  Files           6        6              
  Lines         725      725              
  Branches      176      176              
==========================================
+ Hits          672      673       +1     
+ Misses         50       49       -1     
  Partials        3        3              
Impacted Files Coverage Δ
src/index.js 96.39% <0.00%> (+0.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 704bea9...bae3ce7. Read the comment docs.

@alexander-akait alexander-akait merged commit 7b32255 into master Sep 6, 2021
@alexander-akait alexander-akait deleted the issue-427 branch September 6, 2021 15:11
Copy link

@benquarmby benquarmby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for coming back to theming 💯
Take comments with a pinch of 🧂
FYI @greg-a-smith

{
resourceQuery: "?dark",
use: [
Self.loader,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reference to Self. Should it be like this?

Suggested change
Self.loader,
MiniCssExtractPlugin.loader,

(same for next two occurrences)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for tests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I saw the tests. But this is the README right?

// eslint-disable-next-line no-console
console.log(`LOADING THEME - ${newTheme}`);

import(/* webpackChunkName: "dark" */ "./style.scss?dark").then(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the chunk name comment required here, or is it optional? If it's required, would there be any way to define it in the webpack config rather than the source?

Just thinking out loud: It might be possible to use a pitching loader to expand a static ./style.scss import to one per theme (i.e. ../style.scss?dark, ./style.scss?light, ./style.scss?n...), and then use matching resource queries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for tests and examples, for production I recommend to not use comments, because you will have less names for files, so you will send less bytes for client

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thank you. Would it make sense to revise this example to use production best practices?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to send a PR and fix it

Copy link

@benquarmby benquarmby Sep 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can certainly fix the Self references in the README. Stand by for that.

However, I don't actually know how to replace webpackChunkName comments with something more first class (for example, something we'd see in webpack.config.js). This is one of the reasons I've been following this issue so closely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants