jtenner / parcel-plugin-pegjs

A parcel plugin for pegjs-dev
MIT License
4 stars 1 forks source link

Output optimization #2

Open cedeber opened 5 years ago

cedeber commented 5 years ago

Hello again,

I just realized that the current parcel plugin also integrates the pegjs code into the bundle. As it is not needed because the parser has been produced by the plugin at build time, I tried to get rid of this part.

And apparently the code bellow does solve this issue:

const peg = require('pegjs');
const { Asset } = require('parcel-bundler');

class PEGJSAsset extends Asset {
  constructor(...args) {
    super(...args);
    this.type = 'js';
  }
  async parse(code) {
    return peg.generate(code, {
      format: 'commonjs',
      output: 'source',
    })
  }
  async generate() {
    return this.ast;
  }
}

module.exports = PEGJSAsset;

The Parser still works - hopefully ;-) - on our code.

Could you please have a look on it and integrates this if you feel this is good (I can do a pull request from a fork if you don't have time)

Thanks.

jtenner commented 5 years ago

Wow. I had no idea it was bundling pegjs when using the loader. I'm glad to give it a shot today.