Skip to content

Commit

Permalink
feat: export header and Babel preset (#5)
Browse files Browse the repository at this point in the history
These two things are almost identical across our projects already and it
makes a lot of sense to have them shared from a single source.

Babel preset (TypeScript and CSS are optional):
```json
{
  "exclude": ["**/node_modules/**"],
  "presets": [["vis-dev-utils/babel-preset", { "css": true, "ts": true }]]
}
```

Header (reads package.json):
```javascript
import { generateHeader } from "vis-dev-utils";

const banner = generateHeader();
```

custom values can be supplied if necessary (tsdoc included):
```javascript
const banner = generateHeader({ name: 'vis-timeline and vis-graph2d' });
```
  • Loading branch information
Thomaash committed Dec 30, 2019
1 parent 72ce836 commit ba46072
Show file tree
Hide file tree
Showing 13 changed files with 1,151 additions and 129 deletions.
17 changes: 2 additions & 15 deletions .babelrc
@@ -1,17 +1,4 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": "maintained node versions",
"useBuiltIns": "usage",
"corejs": 3
}
],
"@babel/preset-typescript"
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
]
"exclude": ["**/node_modules/**"],
"presets": [["./babel-preset", { "ts": true }]]
}
2 changes: 2 additions & 0 deletions .eslintignore
@@ -1,3 +1,5 @@
!/.eslintrc
/bin
/declarations
/dist
/lib
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -20,5 +20,7 @@

# built files
/bin
/declarations
/dist
/vis-dev-util-0.0.0-no-version.tgz
/lib
/vis-dev-utils-0.0.0-no-version.tgz
75 changes: 75 additions & 0 deletions babel-preset/index.js
@@ -0,0 +1,75 @@
module.exports = function(_context, { css = false, ts = false } = {}) {
const base = {
presets: [
[
require("@babel/preset-env"),
{
targets: {
// A browser is polyfilled if it is supported by it's maintainers
// or if it is used by at least one in every thousand of users.
browsers: "> 0.1% or not dead",
// This forces Babel to polyfill ESM as if it was UMD. The reason
// behind this is that that Babel doesn't include IE 11 polyfills
// in ESM builds since IE 11 can't even load them. However many of
// our users use bundlers to bundle ESM builds into IE 11
// compatible UMD builds. Therefore even ESM builds need IE 11
// polyfills.
esmodules: false
},
// This would pollute global scope. Babel's Transform Runtime plugin
// is used instead.
useBuiltIns: false
}
]
],
plugins: [
require("@babel/plugin-proposal-class-properties"),
require("@babel/plugin-proposal-object-rest-spread"),
[
require("@babel/plugin-transform-runtime"),
{
// Force corejs 3. The default corejs 2 is deprecated and doesn't
// contain some polyfills.
corejs: 3
}
]
],
env: {
test: {
presets: [
[
require("@babel/preset-env"),
{
// Tests run in Node so there's no need to include any other
// polyfills (we're testing our code, not the polyfills).
targets: "maintained node versions"
}
]
]
},
"test-cov": {
presets: [
[
require("@babel/preset-env"),
{
// dtto
targets: "maintained node versions"
}
]
],
// This instruments the code to record coverage. It's more reliable if
// done through Babel plugin.
plugins: ["istanbul"]
}
}
};

if (css) {
base.plugins.push(require("babel-plugin-css-modules-transform"));
}
if (ts) {
base.presets.push(require("@babel/preset-typescript"));
}

return base;
};
44 changes: 0 additions & 44 deletions lib/header.js

This file was deleted.

0 comments on commit ba46072

Please sign in to comment.