Skip to content
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

feat: add support for link preload/prefetch #1043

Merged
merged 9 commits into from
Apr 16, 2024

Conversation

FogelAI
Copy link
Contributor

@FogelAI FogelAI commented Jul 14, 2023

This PR contains a:

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

Motivation / Use-Case

This pull request adds webpackPrefetch and webpackPreload magic comments support of webpack at import() for css files, per this issue: #142.

It is also an alternative realization of #344 and #488 pull requests, which are not merged and are not active.

See also webpack/webpack#7056 pull request of webpack repository.

Breaking Changes

No breaking changes.

Additional Info

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 14, 2023

CLA Not Signed

@grybykm
Copy link

grybykm commented Jul 25, 2023

@alexander-akait is it ok to merge this one?

@alexander-akait
Copy link
Member

@grybykm @FogelAI Sorry for delay, yes, code is fine, but we need tests for it

@FogelAI
Copy link
Contributor Author

FogelAI commented Mar 13, 2024

Hi @alexander-akait
I have added the tests.
Please note that the commit b785fd8 is the CSS version of webpack/webpack@f5dab1b.

@alexander-akait
Copy link
Member

@FogelAI Can you accept CLA?

]),
"}",
])};`
: "// no preloaded",
Copy link
Member

Choose a reason for hiding this comment

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

Did you copy this code from webpack?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, with adjustments to CSS.
Except for the getLinkElements function that I added (b785fd8).

Copy link
Member

Choose a reason for hiding this comment

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

I want to finish - webpack/webpack#18190, i.e. for built-in CSS support, then I will check code here, regaridng - getLinkElements, it is an intresting question, because I think browsers make different things - webpack/webpack#17497, we need to report about to chrome bug tracker, if it is a bug, they need to fix it, if not - I will improve our code late

src/index.js Outdated
`}`,
`return loadedLinks;`,
]),
`};`,
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove getLinkElements from here too

Copy link
Member

Choose a reason for hiding this comment

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

It will be another investigation

src/index.js Outdated
} = /** @type {Compilation} */ (this.compilation);
const chunkMap = getCssChunkObject(
/** @type {Chunk} */ (chunk),
/** @type {Compilation} */ (this.compilation)
);
const { globalObject } = runtimeTemplate;
const { linkPreload, linkPrefetch } =
JsonpChunkLoadingRuntimeModule.getCompilationHooks(compilation);
Copy link
Member

Choose a reason for hiding this comment

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

Please put these hooks here, i.e. just copy/paste, because this plugin can work not only with Jsonp, also with ESM modules

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

Successfully merging this pull request may close these issues.

3 participants