-
-
Save coolreader18/c15cb2e0e8483d6c69769a0b8ade20a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import compile from "nearley/lib/compile"; | |
import generate from "nearley/lib/generate"; | |
import nearley from "nearley/lib/nearley"; | |
import rawGrammar from "nearley/lib/nearley-language-bootstrapped"; | |
import path from "path"; | |
import rollup from "rollup"; | |
import typescript from "rollup-plugin-typescript2"; | |
const nearleyGrammar = nearley.Grammar.fromCompiled(rawGrammar); | |
function nearleyPlugin() { | |
/** @type rollup.Plugin */ | |
const plug = { | |
name: "nearley", | |
transform(source, id) { | |
if (!id.endsWith(".ne")) return null; | |
const parser = new nearley.Parser(nearleyGrammar); | |
parser.feed(source); | |
const stderr = Object.getOwnPropertyDescriptor(process, "stderr"); | |
Object.defineProperty(process, "stderr", { value: { write: () => {} } }); | |
const compilation = compile(parser.results[0], { | |
file: id | |
}); | |
Object.defineProperty(process, "stderr", stderr); | |
const code = generate(compilation, path.basename(id)); | |
return { code }; | |
} | |
}; | |
return plug; | |
} | |
/** @type rollup.InputOptions */ | |
const config = { | |
experimentalCodeSplitting: true, | |
output: { | |
dir: "dist", | |
format: "cjs" | |
}, | |
input: { | |
lib: "./src/lib/index.ts", | |
cli: "./src/cli/index.ts", | |
plugin: "./src/lib/lib.ts" | |
}, | |
plugins: [ | |
nearleyPlugin(), | |
typescript({ | |
include: ["*.ts+(|x)", "**/*.ts+(|x)", "*.ne", "**/*.ne"] | |
// verbosity: 3 | |
}) | |
], | |
external: id => /^[^\\/.]/.test(id) | |
}; | |
export default config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment