带有Webpack的Antlr JavaScript [英] Antlr javascript with webpack
问题描述
我正在尝试将Webpack与antlr 4 javascript目标一起使用.我正在关注这份文件. https://github.com/antlr/antlr4/blob/master/doc/javascript-target.md
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
如果我理解正确,则webpack会将来自antlr4 javascript运行时库librarty的所有文件与生成的文件(Lexer.js,Listener.js和Parser.js)合并到一个文件中.我只需要在HTML中包含这个文件即可.
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.
在要求排除node.js模块的地方,我不理解文档的这一部分.有人可以解释为什么需要此行吗?
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?
在
webpack.config
文件中,排除使用以下内容的仅node.js模块:node: { module: "empty", net: "empty", fs: "empty" }
In the
webpack.config
file, exclude node.js only modules using:node: { module: "empty", net: "empty", fs: "empty" }
我也没有任何自定义侦听器或访问者.我可以忽略这些步骤吗?我没有创建任何带有指向我的解析代码入口点的index.js文件.
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.
- 通过使用"require"加载您的自定义侦听器或访问者以及相关代码来编写解析树处理代码.
- 创建一个index.js文件,其中包含指向您的解析代码的入口(或多个,如果需要).**
- 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).**
推荐答案
我了解为什么我需要在webpack.config.js中进行此配置.如果我没有此配置
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"
},
运行webpack命令时出现以下错误:-
I get below error while running webpack command:-
错误 找不到模块:错误:无法解析/node_modules/antlr4中的模块'fs' @ ./~antlr4/FileStream.js 38:20-33
ERROR in ./~/antlr4/FileStream.js Module not found: Error: Cannot resolve module 'fs' in /node_modules/antlr4 @ ./~antlr4/FileStream.js 38:20-33
违规行是
var fs = isNodeJs ? require("FS") : null;
这篇关于带有Webpack的Antlr JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!