Skip to content

Commit b870ca4

Browse files
committed
Support for custom HAX themes; through importmap and new rollup-config
1 parent 58fc82b commit b870ca4

File tree

4 files changed

+66
-30
lines changed

4 files changed

+66
-30
lines changed

src/boilerplate/site/custom/package.json

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111
"start": "yarn run watch",
1212
"watch": "rollup --watch -c rollup.config.js"
1313
},
14-
"dependencies": {
15-
},
1614
"devDependencies": {
17-
"@babel/plugin-transform-modules-amd": "^7.2.0",
18-
"@babel/core": "^7.3.3",
19-
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
20-
"@babel/plugin-syntax-import-meta": "^7.2.0",
21-
"@babel/polyfill": "^7.0.0",
22-
"@babel/preset-env": "^7.0.0",
23-
"rollup-plugin-terser": "5.2.0",
24-
"rollup-plugin-rewrite-imports": "^2.0.0",
25-
"rollup": "^1.6.0"
15+
"rollup": "^2.0.0",
16+
"rollup-plugin-terser": "7.0.2",
17+
"@rollup/plugin-node-resolve": "16.0.0",
18+
"@web/rollup-plugin-html": "^2.3.0",
19+
"rollup-plugin-rewrite-imports": "2.0.0",
20+
"@web/rollup-plugin-import-meta-assets": "^2.2.1",
21+
"rollup-plugin-esbuild": "6.1.1",
22+
"@rollup/plugin-babel": "6.0.4"
2623
}
27-
}
24+
}
Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
// @ts-nocheck
2-
const { terser } = require('rollup-plugin-terser');
3-
const rewriteImports = require('rollup-plugin-rewrite-imports');
4-
const production = true;
5-
module.exports = function() {
6-
return {
7-
input: 'src/custom.js',
8-
treeshake: !!production,
9-
output: {
10-
file: `build/custom.es6.js`,
11-
format: 'esm',
12-
sourcemap: false,
13-
},
14-
plugins: [
15-
rewriteImports(`../../build/es6/node_modules/`),
16-
// only minify if in production
17-
production && terser(),
18-
],
19-
};
2+
import nodeResolve from '@rollup/plugin-node-resolve';
3+
import babel from '@rollup/plugin-babel';
4+
import { importMetaAssets } from '@web/rollup-plugin-import-meta-assets';
5+
import esbuild from 'rollup-plugin-esbuild';
6+
7+
const inputFile = "src/custom.js";
8+
export default {
9+
input : inputFile,
10+
output: {
11+
file: `build/custom.es6.js`,
12+
format: 'es',
13+
sourcemap: false,
14+
},
15+
external: (assetPath) => {
16+
// remove current working directory for eval
17+
let asset = assetPath.replace(process.cwd(), '');
18+
// matches input file, or starts with ./ or /src/ then we know it's a local file for processing
19+
// the goal is to be able to correctly reference @haxtheweb / other project bare assets
20+
// and correctly assess that they are to be treated as 'external'
21+
// @todo read off of wc-registry.json to make this assessment if local or otherwise need to hit a CDN based copy
22+
if (asset.endsWith(inputFile) || asset.startsWith('./') || asset.startsWith('/src/')) {
23+
return false;
24+
}
25+
return true;
26+
},
27+
preserveEntrySignatures: false,
28+
plugins: [
29+
/** Resolve bare module imports */
30+
nodeResolve(),
31+
/** Minify JS, compile JS to a lower language target */
32+
esbuild({
33+
minify: true,
34+
target: ['chrome64', 'firefox67', 'safari11.1'],
35+
}),
36+
/** Bundle assets references via import.meta.url */
37+
importMetaAssets(),
38+
/** Minify html and css tagged template literals */
39+
babel(),
40+
],
2041
};

src/boilerplate/site/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<!DOCTYPE html>
22
<html lang="en-US">
33
<head>
4+
<script type="importmap">
5+
{
6+
"scopes": {
7+
"./custom/build/": {
8+
"@haxtheweb/": "./build/es6/node_modules/@haxtheweb/"
9+
}
10+
}
11+
}
12+
</script>
413
<meta charset="utf-8">
514
<link rel="preconnect" crossorigin href="https://fonts.googleapis.com">
615
<link rel="preconnect" crossorigin href="https://cdnjs.cloudflare.com">

src/boilerplate/site/index.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
<!DOCTYPE html>
1515
<html lang="<?php print $HAXSiteConfig->getLanguage(); ?>">
1616
<head>
17+
<script type="importmap">
18+
{
19+
"scopes": {
20+
"./custom/build/": {
21+
"@haxtheweb/": "./build/es6/node_modules/@haxtheweb/"
22+
}
23+
}
24+
}
25+
</script>
1726
<?php print $HAXSiteConfig->getBaseTag(); ?>
1827
<?php print $HAXSiteConfig->getSiteMetadata($HAXSiteConfig->page); ?>
1928
<?php print $HAXSiteConfig->getServiceWorkerScript(null, FALSE, $HAXSiteConfig->getServiceWorkerStatus()); ?>

0 commit comments

Comments
 (0)