Skip to content

Commit 3babeae

Browse files
committed
simplify rollup build and add browserslist config
1 parent b3aaab3 commit 3babeae

File tree

8 files changed

+116
-159
lines changed

8 files changed

+116
-159
lines changed

.browserslistrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
edge >= 81
2+
firefox >= 54
3+
chrome >= 51
4+
safari >= 12
5+
ios >= 11
6+
not ie <= 11

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
<h2 align="center">👾 OmDomDom</h2>
2-
<p align="center">Create, render, and patch virtual DOMs</p>
1+
<h2 align="center">👾 Omdomdom</h2>
2+
<p align="center">Create, render, and patch virtual nodes</p>
33
<br>
44
<p align="center">
55
<a href="https://www.npmjs.com/package/omdomdom"><img src="https://img.shields.io/npm/v/omdomdom.svg?sanitize=true" alt="Version"></a>
66
<a href="https://www.npmjs.com/package/omdomdom"><img src="https://img.shields.io/npm/l/omdomdom.svg?sanitize=true" alt="License"></a>
77
<a href="https://www.npmjs.com/package/omdomdom"><img src="https://badgen.net/circleci/github/geotrev/omdomdom/main" alt="Circle CI status (main)" /></a>
88
<a href="https://www.npmjs.com/package/omdomdom"><img src="https://badgen.net/bundlephobia/minzip/omdomdom" alt="bundle size" /></a>
9-
<a href="https://www.npmjs.com/package/omdomdom"><img src="https://badgen.net/david/dev/geotrev/omdomdom" alt="devDependencies" /></a>
9+
<a href="https://www.libraries.io/npm/omdomdom"><img src="https://img.shields.io/librariesio/release/npm/omdomdom" alt="dependency status" /></a>
1010
</p>
1111

12-
OmDomDOm is intentionally very minimal. It doesn't utilize tagged template literals and therefore is binding-free.
12+
Omdomdom is intentionally very minimal. Its primary function is to produce HTML nodes from strings.
1313

1414
Pull requests and issues welcome!
1515

@@ -51,7 +51,7 @@ patch(...)
5151
></script>
5252
```
5353

54-
The CDN will set `window.OmDomDom` on your page.
54+
The CDN will set `window.Omdomdom` on your page.
5555

5656
## Virtual Node Structure
5757

@@ -70,7 +70,7 @@ VirtualNode {
7070
attributes: Object.<attribute: string, value: string>,
7171

7272
// Is set to `true` if a node is an `svg`, which tells
73-
// OmDomDom to treat it, and its children, as such
73+
// Omdomdom to treat it, and its children, as such
7474
isSVGContext: Boolean,
7575

7676
// The content of a "text" or "comment" node
@@ -154,4 +154,4 @@ If you think it can be improved, please contribute. :)
154154

155155
## Support
156156

157-
OmDomDom works in all modern browsers and IE11. It requires no polyfills/dependencies.
157+
Omdomdom works in all modern browsers and IE11. It requires no polyfills/dependencies.

babel.config.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
11
{
2-
"env": {
3-
"test": {
4-
"presets": [["@babel/preset-env", { "targets": { "node": "current" } }]]
5-
},
6-
"build": {
7-
"presets": ["@babel/preset-env"]
8-
},
9-
"publish": {
10-
"presets": ["@babel/preset-env"]
11-
}
12-
}
2+
"presets": ["@babel/preset-env"]
133
}

config/rollup.build.config.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import path from "path"
2+
import babel from "@rollup/plugin-babel"
3+
import { nodeResolve } from "@rollup/plugin-node-resolve"
4+
import { terser } from "rollup-plugin-terser"
5+
6+
const currentDir = process.cwd()
7+
const year = new Date().getFullYear()
8+
9+
const banner = async () => {
10+
const { default: pkg } = await import("../package.json")
11+
12+
return `/*!
13+
* @license MIT (https://github.com/geotrev/omdomdom/blob/master/LICENSE)
14+
* Omdomdom v${pkg.version} (${pkg.homepage})
15+
* Copyright ${year} ${pkg.author}
16+
*/`
17+
}
18+
19+
const Formats = {
20+
CJS: "cjs",
21+
ES: "es",
22+
UMD: "umd",
23+
}
24+
const input = path.resolve(currentDir, "src/index.js")
25+
const basePlugins = [
26+
nodeResolve(),
27+
babel({
28+
babelHelpers: "bundled",
29+
comments: false,
30+
exclude: "node_modules",
31+
}),
32+
]
33+
34+
const terserPlugin = terser({
35+
output: {
36+
comments: (_, comment) => {
37+
const { value, type } = comment
38+
39+
if (type === "comment2") {
40+
return /@preserve|@license|@cc_on/i.test(value)
41+
}
42+
},
43+
},
44+
})
45+
46+
const baseOutput = (format) => ({
47+
banner,
48+
format,
49+
name: "Omdomdom",
50+
sourcemap: true,
51+
})
52+
53+
const outputs = [Formats.ES, Formats.CJS].reduce(
54+
(configs, format) => [
55+
...configs,
56+
{
57+
...baseOutput(format),
58+
file: path.resolve(currentDir, `lib/omdomdom.${format}.js`),
59+
},
60+
{
61+
...baseOutput(format),
62+
file: path.resolve(currentDir, `lib/omdomdom.${format}.min.js`),
63+
plugins: [terserPlugin],
64+
},
65+
],
66+
[
67+
{
68+
...baseOutput(Formats.UMD),
69+
file: path.resolve(currentDir, "dist/omdomdom.js"),
70+
},
71+
{
72+
...baseOutput(Formats.UMD),
73+
file: path.resolve(currentDir, "dist/omdomdom.min.js"),
74+
plugins: [terserPlugin],
75+
},
76+
]
77+
)
78+
79+
export default {
80+
input,
81+
plugins: basePlugins,
82+
output: [...outputs],
83+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { nodeResolve } from "@rollup/plugin-node-resolve"
33
import serve from "rollup-plugin-serve"
44
import livereload from "rollup-plugin-livereload"
55

6-
const TEST_ROOT = path.resolve(__dirname, "test")
7-
const SOURCE_PATH = path.resolve(TEST_ROOT, "test-cases.js")
8-
const OUTPUT_PATH = path.resolve(TEST_ROOT, "bundle.js")
6+
const currentDir = process.cwd()
7+
const TEST_ROOT = path.resolve(currentDir, "test")
8+
const SOURCE_PATH = TEST_ROOT + "/test-cases.js"
9+
const OUTPUT_PATH = TEST_ROOT + "/bundle.js"
910

1011
export default {
1112
input: SOURCE_PATH,

package-lock.json

Lines changed: 12 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
"prepare": "husky install",
1111
"test": "jest",
1212
"test:watch": "jest --watch",
13-
"watch": "rollup -c rollup.config.test.js -w",
14-
"build": "BABEL_ENV=build rollup -c",
15-
"build:publish": "BABEL_ENV=publish rollup -c",
13+
"watch": "rollup -c config/rollup.serve.config.js -w",
14+
"build": "rollup -c config/rollup.build.config.js",
1615
"eslint:check": "eslint -c .eslintrc.json",
1716
"prettier:check": "prettier --config .prettierrc.json --check",
1817
"prettier:write": "prettier --write",
1918
"git:update-origin": "git add . && git commit -m '[npm publish] update metadata & cdn tags' && git push && git push --tags",
2019
"prepublishOnly": "paopu && npm run git:update-origin",
2120
"preversion": "npm test",
22-
"postversion": "npm run build:publish"
21+
"postversion": "npm run build"
2322
},
2423
"devDependencies": {
2524
"@babel/core": "^7.16.7",

rollup.config.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)