prettier/scripts/build/rollup.parser.config.js

73 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-06-28 22:37:33 +03:00
import baseConfig from "./rollup.base.config.js";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import json from "rollup-plugin-json";
import replace from "rollup-plugin-replace";
import uglify from "uglify-es";
import path from "path";
2017-05-29 07:49:41 +03:00
const parser = process.env.parser;
export default Object.assign(baseConfig, {
entry: "src/" + parser + ".js",
dest: "dist/" + path.basename(parser) + ".js",
2017-06-28 22:37:33 +03:00
format: "cjs",
2017-05-29 07:49:41 +03:00
plugins: [
parser.endsWith("typescript")
? replace({
2017-06-28 22:37:33 +03:00
"exports.Syntax =": "1,",
include: "node_modules/typescript-eslint-parser/parser.js"
})
: {},
2017-11-27 05:14:45 +03:00
// In flow-parser 0.59.0 there's a dynamic require: `require(s8)` which not
// supported by rollup-plugin-commonjs, so we have to replace the variable
// by its value before bundling.
parser.endsWith("flow")
2017-11-27 05:14:45 +03:00
? replace({
"require(tf)": 'require("fs")',
2017-11-27 05:14:45 +03:00
include: "node_modules/flow-parser/flow_parser.js"
})
: {},
2017-05-29 07:49:41 +03:00
json(),
resolve({ preferBuiltins: true }),
commonjs(
parser.endsWith("glimmer")
? {
namedExports: {
"node_modules/handlebars/lib/index.js": ["parse"],
"node_modules/simple-html-tokenizer/dist/simple-html-tokenizer.js": [
"EntityParser",
"HTML5NamedCharRefs",
"EventedTokenizer"
],
"node_modules/@glimmer/syntax/dist/modules/index.js": "default",
"node_modules/@glimmer/syntax/dist/modules/es2017/index.js":
"default"
},
ignore: ["source-map"]
}
: {}
),
2017-05-29 07:49:41 +03:00
{
transformBundle(code) {
const result = uglify.minify(code, {});
2017-06-28 22:37:33 +03:00
if (result.error) {
throw result.error;
}
2017-05-29 07:49:41 +03:00
return result;
2017-06-28 22:37:33 +03:00
}
}
2017-05-29 07:49:41 +03:00
],
external: [
2017-06-28 22:37:33 +03:00
"fs",
"buffer",
"path",
"module",
"assert",
"util",
"os",
"crypto"
],
useStrict: !parser.endsWith("flow")
});