mirror of
https://github.com/developit/microbundle.git
synced 2026-01-18 13:56:35 +00:00
Replace nodent with a babel transform plugin
This commit is contained in:
parent
0d7798705b
commit
71cb427dbd
@ -111,4 +111,3 @@ Here's what's coming up for Microbundle:
|
||||
|
||||
[rollup]: https://github.com/rollup/rollup
|
||||
[bublé]: https://github.com/Rich-Harris/buble
|
||||
[nodent]: https://github.com/MatAtBread/nodent-compiler
|
||||
|
||||
23
babel.config.js
Normal file
23
babel.config.js
Normal file
@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
exclude: [
|
||||
'transform-async-to-generator',
|
||||
'proposal-async-generator-functions',
|
||||
'transform-regenerator',
|
||||
],
|
||||
loose: true,
|
||||
targets: {
|
||||
chrome: '58',
|
||||
ie: '11',
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
plugins: [
|
||||
['babel-plugin-transform-async-to-promises', { inlineHelpers: true }],
|
||||
'@babel/plugin-syntax-jsx',
|
||||
],
|
||||
};
|
||||
28
package.json
28
package.json
@ -7,20 +7,15 @@
|
||||
"bin": "dist/cli.js",
|
||||
"scripts": {
|
||||
"build": "npm run -s build:babel && npm run -s build:self",
|
||||
"build:babel": "babel-node src/cli.js --target=node --format cjs src/{cli,index}.js --presets env",
|
||||
"build:babel": "babel-node src/cli.js --target=node --format cjs src/{cli,index}.js",
|
||||
"build:self": "node dist/cli.js --target=node --format cjs src/{cli,index}.js",
|
||||
"prepare": "npm run -s build",
|
||||
"prepare:babel": "babel --presets env src/*.js -d dist && npm t",
|
||||
"prepare:babel": "babel src/*.js -d dist && npm t",
|
||||
"lint": "eslint src",
|
||||
"test": "npm run -s lint && npm run -s build && jest",
|
||||
"release": "npm run -s prepare && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
|
||||
},
|
||||
"repository": "developit/microbundle",
|
||||
"babel": {
|
||||
"presets": [
|
||||
"env"
|
||||
]
|
||||
},
|
||||
"prettier": {
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all",
|
||||
@ -47,10 +42,12 @@
|
||||
"author": "Jason Miller <jason@developit.ca> (http://jasonformat.com)",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"acorn-jsx": "^4.1.1",
|
||||
"@babel/core": "^7.1.6",
|
||||
"@babel/plugin-syntax-jsx": "^7.0.0",
|
||||
"@babel/polyfill": "^7.0.0",
|
||||
"asyncro": "^3.0.0",
|
||||
"autoprefixer": "^9.0.0",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"babel-plugin-transform-async-to-promises": "^0.8.1",
|
||||
"brotli-size": "^0.0.3",
|
||||
"camelcase": "^5.0.0",
|
||||
"chalk": "^2.4.0",
|
||||
@ -58,28 +55,29 @@
|
||||
"es6-promisify": "^6.0.1",
|
||||
"gzip-size": "^5.0.0",
|
||||
"pretty-bytes": "^5.1.0",
|
||||
"rollup": "^0.66.6",
|
||||
"rollup-plugin-buble": "^0.19.2",
|
||||
"rollup": "^0.67.3",
|
||||
"rollup-plugin-babel": "^4.1.0-0",
|
||||
"rollup-plugin-buble": "^0.19.4",
|
||||
"rollup-plugin-bundle-size": "^1.0.1",
|
||||
"rollup-plugin-commonjs": "^9.0.0",
|
||||
"rollup-plugin-es3": "^1.1.0",
|
||||
"rollup-plugin-flow": "^1.1.1",
|
||||
"rollup-plugin-node-resolve": "^3.3.0",
|
||||
"rollup-plugin-nodent": "^0.2.2",
|
||||
"rollup-plugin-postcss": "^1.6.1",
|
||||
"rollup-plugin-preserve-shebang": "^0.1.6",
|
||||
"rollup-plugin-sizes": "^0.4.2",
|
||||
"rollup-plugin-strict-alias": "^1.0.0",
|
||||
"rollup-plugin-terser": "^3.0.0",
|
||||
"rollup-plugin-typescript2": "^0.17.2",
|
||||
"rollup-plugin-typescript2": "^0.18.0",
|
||||
"sade": "^1.4.0",
|
||||
"tiny-glob": "^0.2.0",
|
||||
"tslib": "^1.9.0",
|
||||
"typescript": ">=2.8.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"@babel/cli": "^7.1.5",
|
||||
"@babel/node": "^7.0.0",
|
||||
"@babel/preset-env": "^7.1.6",
|
||||
"directory-tree": "^2.1.0",
|
||||
"eslint": "^5.0.0",
|
||||
"eslint-config-developit": "^1.1.1",
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
import microbundle from '.';
|
||||
import prog from './prog';
|
||||
import { stdout } from './utils';
|
||||
|
||||
47
src/index.js
47
src/index.js
@ -1,4 +1,3 @@
|
||||
import 'acorn-jsx';
|
||||
import fs from 'fs';
|
||||
import { resolve, relative, dirname, basename, extname } from 'path';
|
||||
import chalk from 'chalk';
|
||||
@ -7,8 +6,8 @@ import glob from 'tiny-glob/sync';
|
||||
import autoprefixer from 'autoprefixer';
|
||||
import cssnano from 'cssnano';
|
||||
import { rollup, watch } from 'rollup';
|
||||
import nodent from 'rollup-plugin-nodent';
|
||||
import commonjs from 'rollup-plugin-commonjs';
|
||||
import babel from 'rollup-plugin-babel';
|
||||
import nodeResolve from 'rollup-plugin-node-resolve';
|
||||
import buble from 'rollup-plugin-buble';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
@ -44,6 +43,16 @@ const WATCH_OPTS = {
|
||||
exclude: 'node_modules/**',
|
||||
};
|
||||
|
||||
// Hoist function because something (rollup?) incorrectly removes it
|
||||
function formatSize(size, filename, type, raw) {
|
||||
const pretty = raw ? `${size} B` : prettyBytes(size);
|
||||
const color = size < 5000 ? 'green' : size > 40000 ? 'red' : 'yellow';
|
||||
const MAGIC_INDENTATION = type === 'br' ? 13 : 10;
|
||||
return `${' '.repeat(MAGIC_INDENTATION - pretty.length)}${chalk[color](
|
||||
pretty,
|
||||
)}: ${chalk.white(basename(filename))}.${type}`;
|
||||
}
|
||||
|
||||
export default async function microbundle(options) {
|
||||
let cwd = (options.cwd = resolve(process.cwd(), options.cwd)),
|
||||
hasPackageJson = true;
|
||||
@ -146,15 +155,6 @@ export default async function microbundle(options) {
|
||||
}
|
||||
}
|
||||
|
||||
function formatSize(size, filename, type, raw) {
|
||||
const pretty = raw ? `${size} B` : prettyBytes(size);
|
||||
const color = size < 5000 ? 'green' : size > 40000 ? 'red' : 'yellow';
|
||||
const MAGIC_INDENTATION = type === 'br' ? 13 : 10;
|
||||
return `${' '.repeat(MAGIC_INDENTATION - pretty.length)}${chalk[color](
|
||||
pretty,
|
||||
)}: ${chalk.white(basename(filename))}.${type}`;
|
||||
}
|
||||
|
||||
async function getSizeInfo(code, filename) {
|
||||
const raw = options.raw || code.length < 5000;
|
||||
const gzip = formatSize(await gzipSize(code), filename, 'gz', raw);
|
||||
@ -357,19 +357,18 @@ function createConfig(options, entry, format, writeMeta) {
|
||||
},
|
||||
}),
|
||||
!useTypescript && flow({ all: true, pretty: true }),
|
||||
nodent({
|
||||
exclude: 'node_modules/**',
|
||||
noRuntime: true,
|
||||
promises: true,
|
||||
transformations: {
|
||||
forOf: false,
|
||||
},
|
||||
parser: {
|
||||
plugins: {
|
||||
jsx: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
// Only used for async await
|
||||
!useTypescript &&
|
||||
babel({
|
||||
exclude: 'node_modules/**',
|
||||
plugins: [
|
||||
'@babel/plugin-syntax-jsx',
|
||||
[
|
||||
'babel-plugin-transform-async-to-promises',
|
||||
{ inlineHelpers: true },
|
||||
],
|
||||
],
|
||||
}),
|
||||
!useTypescript &&
|
||||
buble({
|
||||
exclude: 'node_modules/**',
|
||||
|
||||
@ -20,12 +20,12 @@ basic
|
||||
|
||||
|
||||
Build \\"basicLib\\" to dist:
|
||||
211 B: basic-lib.js.gz
|
||||
154 B: basic-lib.js.br
|
||||
210 B: basic-lib.mjs.gz
|
||||
155 B: basic-lib.mjs.br
|
||||
292 B: basic-lib.umd.js.gz
|
||||
228 B: basic-lib.umd.js.br"
|
||||
202 B: basic-lib.js.gz
|
||||
145 B: basic-lib.js.br
|
||||
203 B: basic-lib.mjs.gz
|
||||
145 B: basic-lib.mjs.br
|
||||
280 B: basic-lib.umd.js.gz
|
||||
215 B: basic-lib.umd.js.br"
|
||||
`;
|
||||
|
||||
exports[`fixtures basic-css 1`] = `
|
||||
@ -139,12 +139,12 @@ basic-with-cwd
|
||||
|
||||
|
||||
Build \\"basic\\" to dist:
|
||||
211 B: basic.js.gz
|
||||
154 B: basic.js.br
|
||||
210 B: basic.mjs.gz
|
||||
155 B: basic.mjs.br
|
||||
287 B: basic.umd.js.gz
|
||||
224 B: basic.umd.js.br"
|
||||
202 B: basic.js.gz
|
||||
145 B: basic.js.br
|
||||
203 B: basic.mjs.gz
|
||||
145 B: basic.mjs.br
|
||||
276 B: basic.umd.js.gz
|
||||
208 B: basic.umd.js.br"
|
||||
`;
|
||||
|
||||
exports[`fixtures custom-source 1`] = `
|
||||
@ -167,12 +167,12 @@ custom-source
|
||||
|
||||
|
||||
Build \\"customSource\\" to dist:
|
||||
211 B: custom-source.js.gz
|
||||
154 B: custom-source.js.br
|
||||
210 B: custom-source.mjs.gz
|
||||
155 B: custom-source.mjs.br
|
||||
293 B: custom-source.umd.js.gz
|
||||
226 B: custom-source.umd.js.br"
|
||||
202 B: custom-source.js.gz
|
||||
145 B: custom-source.js.br
|
||||
203 B: custom-source.mjs.gz
|
||||
145 B: custom-source.mjs.br
|
||||
281 B: custom-source.umd.js.gz
|
||||
209 B: custom-source.umd.js.br"
|
||||
`;
|
||||
|
||||
exports[`fixtures custom-source-with-cwd 1`] = `
|
||||
@ -197,12 +197,12 @@ custom-source-with-cwd
|
||||
|
||||
|
||||
Build \\"customSrc\\" to dist:
|
||||
211 B: custom-src.js.gz
|
||||
154 B: custom-src.js.br
|
||||
210 B: custom-src.mjs.gz
|
||||
155 B: custom-src.mjs.br
|
||||
291 B: custom-src.umd.js.gz
|
||||
228 B: custom-src.umd.js.br"
|
||||
202 B: custom-src.js.gz
|
||||
145 B: custom-src.js.br
|
||||
203 B: custom-src.mjs.gz
|
||||
145 B: custom-src.mjs.br
|
||||
279 B: custom-src.umd.js.gz
|
||||
212 B: custom-src.umd.js.br"
|
||||
`;
|
||||
|
||||
exports[`fixtures jsx 1`] = `
|
||||
@ -251,12 +251,12 @@ name-custom-amd
|
||||
|
||||
|
||||
Build \\"customNameAmd\\" to dist:
|
||||
211 B: name-custom-amd.js.gz
|
||||
154 B: name-custom-amd.js.br
|
||||
210 B: name-custom-amd.mjs.gz
|
||||
155 B: name-custom-amd.mjs.br
|
||||
295 B: name-custom-amd.umd.js.gz
|
||||
230 B: name-custom-amd.umd.js.br"
|
||||
202 B: name-custom-amd.js.gz
|
||||
145 B: name-custom-amd.js.br
|
||||
203 B: name-custom-amd.mjs.gz
|
||||
145 B: name-custom-amd.mjs.br
|
||||
283 B: name-custom-amd.umd.js.gz
|
||||
214 B: name-custom-amd.umd.js.br"
|
||||
`;
|
||||
|
||||
exports[`fixtures name-custom-cli 1`] = `
|
||||
@ -279,12 +279,12 @@ name-custom-cli
|
||||
|
||||
|
||||
Build \\"nameCustomCli\\" to dist:
|
||||
211 B: name-custom.js.gz
|
||||
154 B: name-custom.js.br
|
||||
210 B: name-custom.mjs.gz
|
||||
155 B: name-custom.mjs.br
|
||||
294 B: name-custom.umd.js.gz
|
||||
231 B: name-custom.umd.js.br"
|
||||
202 B: name-custom.js.gz
|
||||
145 B: name-custom.js.br
|
||||
203 B: name-custom.mjs.gz
|
||||
145 B: name-custom.mjs.br
|
||||
283 B: name-custom.umd.js.gz
|
||||
215 B: name-custom.umd.js.br"
|
||||
`;
|
||||
|
||||
exports[`fixtures no-pkg 1`] = `
|
||||
@ -306,12 +306,12 @@ no-pkg
|
||||
|
||||
|
||||
Build \\"noPkg\\" to dist:
|
||||
211 B: no-pkg.js.gz
|
||||
154 B: no-pkg.js.br
|
||||
210 B: no-pkg.mjs.gz
|
||||
155 B: no-pkg.mjs.br
|
||||
288 B: no-pkg.umd.js.gz
|
||||
228 B: no-pkg.umd.js.br"
|
||||
202 B: no-pkg.js.gz
|
||||
145 B: no-pkg.js.br
|
||||
203 B: no-pkg.mjs.gz
|
||||
145 B: no-pkg.mjs.br
|
||||
276 B: no-pkg.umd.js.gz
|
||||
217 B: no-pkg.umd.js.br"
|
||||
`;
|
||||
|
||||
exports[`fixtures no-pkg-name 1`] = `
|
||||
@ -334,12 +334,12 @@ no-pkg-name
|
||||
|
||||
|
||||
Build \\"noPkgName\\" to dist:
|
||||
211 B: no-pkg-name.js.gz
|
||||
154 B: no-pkg-name.js.br
|
||||
210 B: no-pkg-name.mjs.gz
|
||||
155 B: no-pkg-name.mjs.br
|
||||
292 B: no-pkg-name.umd.js.gz
|
||||
230 B: no-pkg-name.umd.js.br"
|
||||
202 B: no-pkg-name.js.gz
|
||||
145 B: no-pkg-name.js.br
|
||||
203 B: no-pkg-name.mjs.gz
|
||||
145 B: no-pkg-name.mjs.br
|
||||
280 B: no-pkg-name.umd.js.gz
|
||||
216 B: no-pkg-name.umd.js.br"
|
||||
`;
|
||||
|
||||
exports[`fixtures pretty 1`] = `
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user