diff --git a/.gitignore b/.gitignore
index 4d46d55..b679283 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ coverage/
site/public
site/resources
site/static/js/bundle.js
+site/**/*.dist.js
diff --git a/site/.babelrc b/site/.babelrc
new file mode 100644
index 0000000..1320b9a
--- /dev/null
+++ b/site/.babelrc
@@ -0,0 +1,3 @@
+{
+ "presets": ["@babel/preset-env"]
+}
diff --git a/site/Makefile b/site/Makefile
index b0898e4..aaf513b 100644
--- a/site/Makefile
+++ b/site/Makefile
@@ -2,9 +2,7 @@
all: js site
-js: static/js/bundle.js
-
-static/js/bundle.js: index.js node_modules
+js: node_modules
npm run build
node_modules: package.json
diff --git a/site/layouts/partials/example-single.html b/site/layouts/partials/example-single.html
index a4c9cf0..5eff34a 100644
--- a/site/layouts/partials/example-single.html
+++ b/site/layouts/partials/example-single.html
@@ -1,17 +1,23 @@
{{ $id := .File.ContentBaseName }}
+{{ $dir := .File.Dir }}
{{ .Content }}
{{ range .Resources.Match "*.js" }}
{{ $example := strings.TrimSuffix ".js" .Name }}
+ {{ $distFile := printf "%s/%s.dist.js" $dir $example }}
+ {{ if not (eq ".dist" (path.Ext $example)) }}
+
{{ highlight .Content "javascript" "" }}
+
+ {{ end }}
{{ end }}
diff --git a/site/rollup.config.js b/site/rollup.config.js
index 40fdf0d..e70250f 100644
--- a/site/rollup.config.js
+++ b/site/rollup.config.js
@@ -3,21 +3,46 @@ import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import { terser } from "rollup-plugin-terser";
-let commonPlugins = [
- resolve({
- dedupe: ["flyps"],
- }),
- commonjs(),
- babel({ exclude: "node_modules/**" }),
- terser(),
-];
+import path from "path";
+import fs from "fs";
+
+let listFiles = dir =>
+ fs.readdirSync(dir).reduce((acc, filename) => {
+ let filepath = path.join(dir, filename);
+ if (fs.lstatSync(filepath).isDirectory()) {
+ return [...acc, ...listFiles(filepath)];
+ }
+ return [...acc, filepath];
+ }, []);
-export default [{
- input: "index.js",
- output: {
- file: "static/js/bundle.js",
- format: "umd",
- name: "bundle",
+let examples = listFiles("content/example")
+ .filter(file => file.endsWith(".js") && !file.endsWith(".dist.js"))
+ .map(js => ({
+ input: js,
+ output: {
+ file: path.join(path.dirname(js), path.basename(js, ".js") + ".dist.js"),
+ format: "umd",
+ name: path.basename(js, ".js"),
+ },
+ plugins: [babel({ exclude: "node_modules/**" })],
+ }));
+
+export default [
+ {
+ input: "index.js",
+ output: {
+ file: "static/js/bundle.js",
+ format: "umd",
+ name: "bundle",
+ },
+ plugins: [
+ resolve({
+ dedupe: ["flyps"],
+ }),
+ commonjs(),
+ babel({ exclude: "node_modules/**" }),
+ terser(),
+ ],
},
- plugins: commonPlugins,
-}];
+ ...examples,
+];