Antlr javascript with webpack

做~自己de王妃 提交于 2020-05-15 11:33:50

问题


I am trying to use webpack with antlr 4 javascript target. I am following this document. https://github.com/antlr/antlr4/blob/master/doc/javascript-target.md

If I understand correctly , webpack will merge all the files from antlr4 javascript runtime librarty and the generated files (Lexer.js, Listener.js and Parser.js) in one single file. I need to include only this one file in my html.

I don't understand this part of the document where it's asking to exclude node.js module. Can someone please explain why this line is needed?

In the webpack.config file, exclude node.js only modules using: node: { module: "empty", net: "empty", fs: "empty" }

I also don't have any custom listener or visitor. Can I ignore these steps. I am not creating any index.js file with entry point to my parsing code.

  • write your parse tree handling code by providing your custom listener or visitor, and associated code, using 'require' to load antlr.
  • create an index.js file with the entry point to your parsing code (or several if required).**

回答1:


I understood why I need this configuration in webpack.config.js. If I don't have this configuration

node: {
        module: "empty",
        net:"empty",
        fs: "empty"
    },

I get below error while running webpack command:-

ERROR in ./~/antlr4/FileStream.js Module not found: Error: Cannot resolve module 'fs' in /node_modules/antlr4 @ ./~antlr4/FileStream.js 38:20-33

The offending line is

var fs = isNodeJs ? require("FS") : null;


来源:https://stackoverflow.com/questions/41618709/antlr-javascript-with-webpack

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!