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

Replace content-for using a Vite plugin #1836

Merged
merged 9 commits into from
Apr 17, 2024
Merged

Replace content-for using a Vite plugin #1836

merged 9 commits into from
Apr 17, 2024

Conversation

BlueCutOfficial
Copy link
Collaborator

@BlueCutOfficial BlueCutOfficial commented Mar 5, 2024

This PR moves {{content-for}} from stage 2 to stage 3:

We no longer replace the {{content-for}} snippets in the index.html during the build of the rewritten app. Instead, we leave the {{content-for}} in place and it's a new Vite plugin that performs the replacement. To do so, the Vite plugin relies on a new file content-for.json output during the pre-build.

Breaking change

The new approach supposes that Embroider knows in advance what types of {{content-for}} are provided by the addons, because the Broccoli plugin that builds the dictionary needs to be agnostic from rewritten-app/index.html if we don't want to be tied with stage 2.

The new build option availableContentForTypes allows to extend the list of {{content-for}} types in case an addon provides something custom. For instance, let's suppose your app relies on a classic addon that provides {{content-for "custom"}}, you should add the following build option so the content can be replaced:

// ember-cli-build.js
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { prebuild } = require('@embroider/compat');

module.exports = function (defaults) {
  const app = new EmberApp(defaults, {});
  return prebuild(app, {
    availableContentForTypes: ['custom'],
  });
};

@BlueCutOfficial BlueCutOfficial self-assigned this Mar 12, 2024
@BlueCutOfficial
Copy link
Collaborator Author

BlueCutOfficial commented Apr 9, 2024

The canary-static-app error sounds a bit like the tests not being present but I am not sure how it's related to the PR and how it happens because the command pnpm test: production uses the option FORCE_BUILD_TESTS: 'true'.

The canary-vite-app-basics errors comes from a test using the command node ./scripts/run-tests.mjs that executes the given test file. I am not familiar with that part.

…r}} based on a content-for.json located in the .embroider folder
@BlueCutOfficial BlueCutOfficial marked this pull request as ready for review April 16, 2024 15:08
…acement pattern on the index.html files so the vite plugin can take over
… the compat-app-builder that outputs it as a JSON
…e contentFor utility from ember-app-utils to generate the correct content for each type
Copy link
Member

@mansona mansona left a comment

Choose a reason for hiding this comment

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

Fantastic work 🎉

@mansona mansona added the enhancement New feature or request label Apr 17, 2024
@mansona mansona merged commit fad2387 into embroider-build:main Apr 17, 2024
94 checks passed
@github-actions github-actions bot mentioned this pull request Apr 17, 2024
@BlueCutOfficial BlueCutOfficial deleted the replace-content-for-with-valid-html branch April 17, 2024 13:33
@mansona mansona added breaking and removed enhancement New feature or request labels Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants