-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): inject generated js chunks into theme script tags
- Loading branch information
1 parent
628132a
commit aa1bdab
Showing
6 changed files
with
84 additions
and
3 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
43 changes: 43 additions & 0 deletions
43
packages/nx-shopify/src/webpack/configs/templates/script-tags.html
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,43 @@ | ||
<% for (var chunk in htmlWebpackPlugin.files.js) { %> <% if | ||
(htmlWebpackPlugin.options.isDevServer === true) { %> <% var src = | ||
htmlWebpackPlugin.files.js[chunk] %> <% } else { %> <% var templateName = | ||
htmlWebpackPlugin.files.js[chunk].split('/').reverse()[0].replace('.js', | ||
'').split('.')[1] %> <% var templateFull = | ||
htmlWebpackPlugin.files.js[chunk].split('/').reverse()[0].replace('.js', '') %> | ||
<% var basename = htmlWebpackPlugin.files.js[chunk].split('/').reverse()[0]; %> | ||
<% var src = `{{ '${basename}' | asset_url }}` %> <% } %> <% if (typeof | ||
htmlWebpackPlugin.options.liquidLayouts[templateFull] !== 'undefined') { %> {%- | ||
if layout == '<%= templateName %>' -%} | ||
<script type="text/javascript" src="<%= src %>" defer></script> | ||
{%- else -%} | ||
<link rel="prefetch" href="<%= src %>" as="script" /> | ||
{%- endif -%} <% } else if (chunk.split('@').length > 1) { %> <% var pages = | ||
chunk.split('@') %> <% var conditions = [] %> <% pages.forEach(function(page){ | ||
%> <% var pageTemplate = htmlWebpackPlugin.options.liquidTemplates[page] %> <% | ||
if (typeof pageTemplate !== 'undefined') { %> <% if | ||
(pageTemplate.includes('customers\\') || pageTemplate.includes('customers/')) { | ||
%> <% conditions.push("template == 'customers/" + | ||
page.split('.').slice(1).join('.') + "'") %> <% } else { %> <% | ||
conditions.push("template == '" + page.split('.').slice(1).join('.') + "'") %> | ||
<% } %> <% } else if (typeof htmlWebpackPlugin.options.liquidLayouts[page] !== | ||
'undefined') { %> <% conditions.push("layout == '" + page.split('.')[1] + "'") | ||
%> <% } %> <% }); %> {%- if <%= conditions.join(' or ') %> -%} | ||
<script type="text/javascript" src="<%= src %>" defer></script> | ||
{%- else -%} | ||
<link rel="prefetch" href="<%= src %>" as="script" /> | ||
{%- endif -%} <% } else if (typeof | ||
htmlWebpackPlugin.options.liquidTemplates[templateFull] !== 'undefined') { %> <% | ||
var chunkTemplate = htmlWebpackPlugin.options.liquidTemplates[templateFull] %> | ||
<% if (chunkTemplate.includes('customers\\') || | ||
chunkTemplate.includes('customers/')) { %> {%- if template == 'customers/<%= | ||
chunk.split('.').slice(1).join('.') %>' -%} | ||
<script type="text/javascript" src="<%= src %>" defer></script> | ||
{%- else -%} | ||
<link rel="prefetch" href="<%= src %>" as="script" /> | ||
{%- endif -%} <% } else { %> {%- if template == '<%= templateName %>' -%} | ||
<script type="text/javascript" src="<%= src %>" defer></script> | ||
{%- else -%} | ||
<link rel="prefetch" href="<%= src %>" as="script" /> | ||
{%- endif -%} <% } %> <% } else { %> | ||
<script type="text/javascript" src="<%= src %>" defer></script> | ||
<% } %> <% } %> |
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,2 @@ | ||
export * from './theme-layouts-utils'; | ||
export * from './theme-template-utils'; |
15 changes: 15 additions & 0 deletions
15
packages/nx-shopify/src/webpack/utils/theme-layouts-utils.ts
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,15 @@ | ||
import * as glob from 'glob'; | ||
import * as path from 'path'; | ||
|
||
export function getLayoutEntryPoints(sourceRoot) { | ||
const entrypoints = {}; | ||
|
||
const templatesEntries = glob.sync(`${sourceRoot}/theme/layout/**/*.ts`); | ||
|
||
templatesEntries.forEach((filePath) => { | ||
const entryName = path.parse(filePath).name; | ||
entrypoints[`layout.${entryName}`] = filePath; | ||
}); | ||
|
||
return entrypoints; | ||
} |
File renamed without changes.