mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
DEV: Improve strategy for identifying ember-cli JS chunks (#23382)
Our Ember build compiles assets into multiple chunks. In the past, we used the output from ember-auto-import-chunks-json-generator to give Rails a map of those chunks. However, that addon is specific to ember-auto-import, and is not compatible with Embroider. Instead, we can switch to parsing the html files which are output by ember-cli. These are guaranteed to have the correct JS files in the correct place. A <discourse-chunked-script> will allow us to easily identify which chunks belong to which entrypoint. In future, as we update more entrypoints to be compiled by Embroider/Webpack, we can easily introduce new wrappers. Previously applied in 2c58d45 and reverted in 24d46fd. This version has been updated for subfolder support.
This commit is contained in:
@ -1,9 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe EmberCli do
|
||||
describe "#ember_version" do
|
||||
describe ".ember_version" do
|
||||
it "works" do
|
||||
expect(EmberCli.ember_version).to match(/\A\d+\.\d+/)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".parse_chunks_from_html" do
|
||||
def generate_html
|
||||
<<~HTML
|
||||
<html>
|
||||
<head>
|
||||
<discourse-chunked-script entrypoint="discourse">
|
||||
<script src="#{Discourse.base_path}/assets/firstchunk.js"></script>
|
||||
<script src="#{Discourse.base_path}/assets/secondchunk.js"></script>
|
||||
</discourse-chunked-script>
|
||||
</head>
|
||||
<body>
|
||||
Hello world
|
||||
</body>
|
||||
</html>
|
||||
HTML
|
||||
end
|
||||
|
||||
it "can parse chunks for a normal site" do
|
||||
chunks = EmberCli.parse_chunks_from_html generate_html
|
||||
expect(chunks["discourse"]).to eq(%w[firstchunk secondchunk])
|
||||
end
|
||||
|
||||
it "can parse chunks for a subfolder site" do
|
||||
set_subfolder "/discuss"
|
||||
|
||||
html = generate_html
|
||||
|
||||
# sanity check that our fixture is working
|
||||
expect(html).to include("/discuss/assets/firstchunk.js")
|
||||
|
||||
chunks = EmberCli.parse_chunks_from_html html
|
||||
expect(chunks["discourse"]).to eq(%w[firstchunk secondchunk])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user