Skip to content

Commit

Permalink
Enable development and production bundling with Webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
octogonz committed Feb 1, 2021
1 parent e50ecf4 commit 4716a89
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
5 changes: 3 additions & 2 deletions runtime/JavaScript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -25,7 +26,7 @@
"ini": "1.3.6"
},
"scripts": {
"build": "webpack"
"build": "webpack --mode=development && webpack --mode=production"
},
"engines": {
"node": ">=14"
Expand Down
56 changes: 30 additions & 26 deletions runtime/JavaScript/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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',
},
},
],
},
};
};

0 comments on commit 4716a89

Please sign in to comment.