带有 webpack 的 Antlr javascript [英] Antlr javascript with webpack

查看:37
本文介绍了带有 webpack 的 Antlr javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 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 运行时库中的所有文件和生成的文件(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"加载 antlr 来编写解析树处理代码.
  • 创建一个 index.js 文件,其中包含解析代码的入口点(或多个,如果需要).**

推荐答案

我明白为什么我需要在 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:-

./~/antlr4/FileStream.js 中的错误找不到模块:错误:无法解析/node_modules/antlr4 中的模块fs"@ ./~antlr4/FileStream.js 38:20-33

违规行是

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

这篇关于带有 webpack 的 Antlr javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆