-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at Webpack manifest support for JS/CSS output bundles (#6)
* First pass at Webpack manifest support for js/css * Rename tag webpack_path and add feature tests
- Loading branch information
1 parent
7467cc6
commit a344661
Showing
18 changed files
with
363 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
Feature: WebpackPath Tag | ||
As a web developer who likes managing frontend assets with Webpack | ||
I want to be able to easily link JS and CSS output bundles using manifest.json | ||
So browsers don't use cached, out-of-date bundles | ||
|
||
Scenario: Use Webpack manifest | ||
Given I have a _layouts directory | ||
And I have a "_layouts/default.html" file with content: | ||
""" | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="{% webpack_path css %}" /> | ||
<script src="{% webpack_path js %}" defer></script> | ||
</head> | ||
<body> | ||
{{ content }} | ||
</body> | ||
</html> | ||
""" | ||
And I have an "index.html" page with layout "default" that contains "page content" | ||
And I have a ".bridgetown-webpack" directory | ||
And I have a ".bridgetown-webpack/manifest.json" file with content: | ||
""" | ||
{ | ||
"main.js": "all.hashgoeshere.js", | ||
"main.css": "all.hashgoeshere.css" | ||
} | ||
""" | ||
When I run bridgetown build | ||
Then the "output/index.html" file should exist | ||
And I should see "/_bridgetown/static/js/all.hashgoeshere.js" in "output/index.html" | ||
And I should not see "MISSING_WEBPACK_MANIFEST" in "output/index.html" | ||
|
||
Scenario: Missing Webpack manifest | ||
Given I have a _layouts directory | ||
And I have a "_layouts/default.html" file with content: | ||
""" | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="{% webpack_path css %}" /> | ||
<script src="{% webpack_path js %}" defer></script> | ||
</head> | ||
<body> | ||
{{ content }} | ||
</body> | ||
</html> | ||
""" | ||
And I have an "index.html" page with layout "default" that contains "page content" | ||
When I run bridgetown build | ||
Then the "output/index.html" file should exist | ||
And I should see "MISSING_WEBPACK_MANIFEST" in "output/index.html" | ||
|
||
Scenario: Missing Webpack manifest | ||
Given I have a _layouts directory | ||
And I have a "_layouts/default.html" file with content: | ||
""" | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="{% webpack_path bad %}" /> | ||
</head> | ||
<body> | ||
{{ content }} | ||
</body> | ||
</html> | ||
""" | ||
And I have an "index.html" page with layout "default" that contains "page content" | ||
And I have a ".bridgetown-webpack" directory | ||
And I have a ".bridgetown-webpack/manifest.json" file with content: | ||
""" | ||
{ | ||
"main.js": "all.hashgoeshere.js", | ||
"main.css": "all.hashgoeshere.css" | ||
} | ||
""" | ||
When I run bridgetown build | ||
Then the "output/index.html" file should not exist | ||
And I should see "Liquid Exception" in the build output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bridgetown | ||
module Tags | ||
class WebpackPath < Liquid::Tag | ||
include Bridgetown::Filters::URLFilters | ||
|
||
def initialize(tag_name, asset_type, tokens) | ||
super | ||
|
||
# js or css | ||
@asset_type = asset_type.strip | ||
end | ||
|
||
def render(context) | ||
@context = context | ||
site = context.registers[:site] | ||
|
||
frontend_path = relative_url("_bridgetown/static") | ||
|
||
manifest_file = site.in_root_dir(".bridgetown-webpack", "manifest.json") | ||
if File.exist?(manifest_file) | ||
manifest = JSON.parse(File.read(manifest_file)) | ||
if @asset_type == "js" | ||
js_path = manifest["main.js"].split("/").last | ||
[frontend_path, "js", js_path].join("/") | ||
elsif @asset_type == "css" | ||
css_path = manifest["main.css"].split("/").last | ||
[frontend_path, "css", css_path].join("/") | ||
else | ||
Bridgetown.logger.error("Unknown Webpack asset type", @asset_type) | ||
nil | ||
end | ||
else | ||
"MISSING_WEBPACK_MANIFEST" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Liquid::Template.register_tag("webpack_path", Bridgetown::Tags::WebpackPath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bridgetown | ||
VERSION = "0.10.0" | ||
VERSION = "0.10.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ node_modules | |
.sass-cache | ||
.bridgetown-cache | ||
.bridgetown-metadata | ||
.bridgetown-webpack | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ node_modules | |
.sass-cache | ||
.bridgetown-cache | ||
.bridgetown-metadata | ||
.bridgetown-webpack | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.