embroider-build / embroider

Compiling Ember apps into spec-compliant, modern Javascript.
MIT License
339 stars 137 forks source link

Supporting overwrites for extra public trees #693

Open lukecoy opened 3 years ago

lukecoy commented 3 years ago

Should Embroider expose a mechanism to support overwriting parts of the build tree? Context below.


When building an embroider project with HTML files in public/*.html, JSDOM will attempt to serialize the contents of those files, which will potentially change its contents. For example:

this HTML file: foo bar serializes into this in dist/: <html><head></head><body>foo bar</body></html>

I'm not sure if this is expected behavior or not (ember-cli does not currently do this), but to override this behavior, I do:

// ember-cli-build.js
const embroiderTree = require('@embroider/compat').compatBuild(...);
...
return broccoliMergeTrees(
    [embroiderTree, Funnel('public', { files: ['foobar.html'] })],
    { overwrite: true }
);

... this works fine, but curious if there's a native mechanism to support something like this, similar to what extraPublicTrees accomplishes. Thanks!

ef4 commented 3 years ago

The only reason extraPublicTrees exists as an argument is because when we replace app.toTree() with compatBuild(), people who were before passing the optional extra argument into toTree need a place to put it. It's a compatibility feature, and in general customizing anything about your embroider build output via broccoli is strongly discouraged.

But that's not really the right solution here anyway. I think what you might need is a way to control which html files embroider considers as entrypoints.

But also, what is actually being broken by this rewriting? Because the rewriting is spec-compliant: browsers were already interpreting your file that way.

lukecoy commented 3 years ago

But also, what is actually being broken by this rewriting? Because the rewriting is spec-compliant: browsers were already interpreting your file that way.

@ef4 - Agreed, HTML should be formatted this way anyways. My usage is a weird edge case involving the google site verification HTML file, which is consumed by SEO tooling. It's a HTML file with raw text, no elements. Unfortunately, the Google Admin Console wont work with the serialized HTML output.