Create JS library paths relative to HTML#10
Open
agarzola wants to merge 1 commit intodrupal-pattern-lab:masterfrom
Open
Create JS library paths relative to HTML#10agarzola wants to merge 1 commit intodrupal-pattern-lab:masterfrom
agarzola wants to merge 1 commit intodrupal-pattern-lab:masterfrom
Conversation
This is a more resilient solution since it doesn’t rely on Pattern Lab being served from the theme directory.
|
Exactly what we have done with our themes, set relative path I'm glad same works for others in different scenario, as wasn't certain if it was just our setup or depth of components that meant the 4 level relative prefix worked. |
Author
|
Thanks for linking to that PR, @waako. I hadn’t noticed #2, but I do think this solution is simpler, since —as far as I can tell— Although I could be missing something. My experience with this is limited to its use within Emulsify. |
|
What I was trying to say is that I completely agree with you and this PR, it seems to be the most effective and simple way and works for us too. |
Author
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
This PR modifies the
attach_libraryfunction to produce JS library paths that are relative to the generated component HTML documents, rather than to the root of the site.(Long-winded) Background
We’re using Emulsify and have CI automatically building a static version of Pattern Lab so developers and stakeholders can review the patterns on the live environment. This saves us having to keep a separate Node process running to serve from the theme directory. We access the pattern library via a URL that looks like this:
To accomplish this, our deployment script simply navigates to the theme directory, installs dependencies, and invokes a script that builds static files, like so:
Where the
buildscript in our theme’spackage.jsonis as follows:Note that
gulp buildsimply invokes this task inemulsify-gulp. The result is a navigable set of static Pattern Lab files that point to../../../../dist/style.cssfor CSS andscripttags that point to/dist/path_to_component/component_name.js, i.e. while CSS paths are relative to the HTML document, JS paths are relative to the root of the site.To illustrate the problem with this in our scenario, here’s that sample URL again with some notes:
Note that using paths relative to the root of the site works correctly when serving Pattern Lab from the theme directory (i.e. when using
npm start) becausedist/happens to be at the root level in that context. However, this is brittle, because it requires Pattern Lab to be served from the theme directory in order for JS paths to work.This PR addresses this problem by producing JS library paths that, much like the
style.csspath, are relative to the component’s HTML file, and not to the root of the site, which enables us to access Pattern Lab in the way described above while continuing to support the server run by Emulsify’snpm start.