From 4716a897e39c2138076ef342c831b6b8afa91398 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Sun, 31 Jan 2021 21:38:45 -0800 Subject: [PATCH] Enable development and production bundling with Webpack --- runtime/JavaScript/package.json | 5 ++- runtime/JavaScript/webpack.config.js | 56 +++++++++++++++------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/runtime/JavaScript/package.json b/runtime/JavaScript/package.json index d5a2184845..5640c421b8 100644 --- a/runtime/JavaScript/package.json +++ b/runtime/JavaScript/package.json @@ -2,7 +2,8 @@ "name": "antlr4", "version": "4.9.1", "description": "JavaScript runtime for ANTLR4", - "main": "src/antlr4/index.js", + "main": "src/index.js", + "module": "dist/antlr4.js", "repository": "antlr/antlr4.git", "keywords": [ "lexer", @@ -25,7 +26,7 @@ "ini": "1.3.6" }, "scripts": { - "build": "webpack" + "build": "webpack --mode=development && webpack --mode=production" }, "engines": { "node": ">=14" diff --git a/runtime/JavaScript/webpack.config.js b/runtime/JavaScript/webpack.config.js index 7b2fead63e..95f7149098 100644 --- a/runtime/JavaScript/webpack.config.js +++ b/runtime/JavaScript/webpack.config.js @@ -1,28 +1,32 @@ const path = require('path'); -module.exports = { - mode: "production", - entry: './src/antlr4/index.js', - output: { - filename: 'antlr4.js', - path: path.resolve(__dirname, 'dist'), - // the name of the exported antlr4 - library: "antlr4", - libraryTarget: 'window' - }, - node: { - module: "empty", - net: "empty", - fs: "empty" - }, - target: "web", - module: { - rules: [{ - test: /\.js$/, - exclude: /node_modules/, - use: { - loader: 'babel-loader', - } - }] - } -} +module.exports = (env, argv) => { + return { + entry: './src/antlr4/index.js', + output: { + filename: + argv.mode === 'production' ? 'antlr4.min.js' : 'antlr4.js', + path: path.resolve(__dirname, 'dist'), + // the name of the exported antlr4 + library: 'antlr4', + libraryTarget: 'umd', + }, + node: { + module: 'empty', + net: 'empty', + fs: 'empty', + }, + target: 'web', + module: { + rules: [ + { + test: /\.js$/, + exclude: /node_modules/, + use: { + loader: 'babel-loader', + }, + }, + ], + }, + }; +};