From e0ea2fecfd673366bcd6489b75d6d3eb15fc93da Mon Sep 17 00:00:00 2001 From: George Treviranus Date: Sat, 15 Jan 2022 23:24:21 -0800 Subject: [PATCH] feat: adds snabbdom browser bundle support --- README.md | 28 +++++++++++++++++++++++- config/rollup.build.config.js | 40 +++++++++++++++++++++++++++++------ paopu.config.json | 4 ++++ test/jsx/index.html | 30 +++++++++++++++++++++++++- test/template/index.html | 4 ---- vendor/snabbdom.js | 1 + 6 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 vendor/snabbdom.js diff --git a/README.md b/README.md index 7a4a96b..a031a23 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,9 @@ $ npm i rotom Use the CDN to skip packaging and use the library from the cloud. -First, include the renderer: +First, include a renderer (only one): + +**Omdomdom**: ```html @@ -67,6 +69,30 @@ First, include the renderer: > ``` +**Snabbdom**: + +```html + + + + + +``` + +Note that Snabbdom doesn't build its own browser bundle so Rotom provides it. + +--- + And Rotom itself (after the renderer script): ```html diff --git a/config/rollup.build.config.js b/config/rollup.build.config.js index 095da3a..9e94bae 100644 --- a/config/rollup.build.config.js +++ b/config/rollup.build.config.js @@ -97,25 +97,25 @@ function createProdOutputs(type) { function createLibConfigs() { return [ { - input: path.resolve(currentDir, `src/rotom.jsx.js`), + input: path.resolve(currentDir, "src/rotom.jsx.js"), output: createDevOutputs(RenderTypes.JSX), external, plugins: [...plugins, replacePlugin(Environments.DEVELOPMENT)], }, { - input: path.resolve(currentDir, `src/rotom.jsx.js`), + input: path.resolve(currentDir, "src/rotom.jsx.js"), output: createProdOutputs(RenderTypes.JSX), external, plugins: [...plugins, replacePlugin(Environments.PRODUCTION)], }, { - input: path.resolve(currentDir, `src/rotom.template.js`), + input: path.resolve(currentDir, "src/rotom.template.js"), output: createDevOutputs(RenderTypes.TEMPLATE), external, plugins: [...plugins, replacePlugin(Environments.DEVELOPMENT)], }, { - input: path.resolve(currentDir, `src/rotom.template.js`), + input: path.resolve(currentDir, "src/rotom.template.js"), output: createProdOutputs(RenderTypes.TEMPLATE), external, plugins: [...plugins, replacePlugin(Environments.PRODUCTION)], @@ -136,7 +136,7 @@ function createDistConfigs() { input: path.resolve(currentDir, "src/rotom.template.js"), output: { ...baseDistOutput, - file: path.resolve(currentDir, `dist/rotom.template.js`), + file: path.resolve(currentDir, "dist/rotom.template.js"), sourcemap: true, }, external, @@ -146,7 +146,7 @@ function createDistConfigs() { input: path.resolve(currentDir, "src/rotom.template.js"), output: { ...baseDistOutput, - file: path.resolve(currentDir, `dist/rotom.template.min.js`), + file: path.resolve(currentDir, "dist/rotom.template.min.js"), sourcemap: true, plugins: [terserPlugin], }, @@ -156,4 +156,30 @@ function createDistConfigs() { ] } -export default [...createLibConfigs(), ...createDistConfigs()] +function createSnabbdomConfig() { + return { + input: path.resolve(currentDir, "vendor/snabbdom.js"), + output: [ + { + file: path.resolve(currentDir, "dist/snabbdom.js"), + format: "umd", + name: "snabbdom", + sourcemap: true, + }, + { + file: path.resolve(currentDir, "dist/snabbdom.min.js"), + format: "umd", + name: "snabbdom", + sourcemap: true, + plugins: [terserPlugin], + }, + ], + plugins, + } +} + +export default [ + createSnabbdomConfig(), + ...createLibConfigs(), + ...createDistConfigs(), +] diff --git a/paopu.config.json b/paopu.config.json index 70964be..19383e5 100644 --- a/paopu.config.json +++ b/paopu.config.json @@ -4,6 +4,10 @@ "resources": ["dist/omdomdom.js", "dist/omdomdom.min.js"], "targets": ["README.md", "test/template/index.html"] }, + "snabbdom": { + "resources": ["dist/snabbdom.js", "dist/snabbdom.min.js"], + "targets": ["README.md", "test/jsx/index.html"] + }, "rotom": { "resources": ["dist/rotom.template.js", "dist/rotom.template.min.js"], "targets": ["README.md", "test/jsx/index.html", "test/template/index.html"] diff --git a/test/jsx/index.html b/test/jsx/index.html index a78eb90..76b948b 100644 --- a/test/jsx/index.html +++ b/test/jsx/index.html @@ -34,6 +34,34 @@ }) - + + + + + + + + + diff --git a/test/template/index.html b/test/template/index.html index 61e707f..458ae29 100644 --- a/test/template/index.html +++ b/test/template/index.html @@ -39,14 +39,12 @@ src="https://cdn.jsdelivr.net/npm/omdomdom@0.3.0/dist/omdomdom.js" integrity="sha256-BpjOyF5QNlVmvIoAucFkb4hr+8+5r0qctp12U3J9cmM=" crossorigin="anonymous" - defer > --> diff --git a/vendor/snabbdom.js b/vendor/snabbdom.js new file mode 100644 index 0000000..59091d8 --- /dev/null +++ b/vendor/snabbdom.js @@ -0,0 +1 @@ +export * as snabbdom from "snabbdom"