Skip to content

Commit

Permalink
Remove lib requirements from webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Nov 30, 2023
1 parent 7d09f27 commit b311d9d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
"ts-loader": "^9.5.0",
"typescript": "^5.2.2",
"webpack": "^5.89.0",
"webpack-bundle-analyzer": "^4.10.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-node-externals": "^3.0.0",
"worker-loader": "^3.0.8"
},
"dependencies": {
Expand Down
31 changes: 4 additions & 27 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
const path = require("path");
const TerserPlugin = require('terser-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const nodeExternals = require('webpack-node-externals');


const PUBLIC_DIR = "public";
const LIBRARY_DIR = "dist";
const DEVELOPMENT_PORT = 8080;
module.exports = function (webpackEnv, argv) {
let mode = argv.mode;
if (!mode) {
mode = webpackEnv.WEBPACK_SERVE ? 'development' : 'production'
}
// In development, the bundle is loaded from the public folder
// In production, node_modules typically use the dist folder
let outFolder = "";
let entries = {};
let externals = [];
if (mode === "development") {
outFolder = PUBLIC_DIR;
entries = Object.fromEntries([
return {
entry: Object.fromEntries([
["App", "./src/App.ts"],
["InputServiceWorker", "./src/InputServiceWorker.ts"]
]);
} else {
outFolder = LIBRARY_DIR;
entries = Object.fromEntries([
["Library", "./src/Library.ts"],
["/workers/input/InputWorker", "./src/workers/input/InputWorker.ts"]
]);
externals = [nodeExternals()];
}
return {
entry: entries,
]),
module: {
rules: [
{
Expand All @@ -56,7 +37,7 @@ module.exports = function (webpackEnv, argv) {
output: {
// Allow generating both service worker and Papyros
filename: "[name].js",
path: path.resolve(__dirname, outFolder),
path: path.resolve(__dirname, PUBLIC_DIR),
// Required to make output useable as an npm package
library: {
name: "Papyros",
Expand Down Expand Up @@ -84,9 +65,5 @@ module.exports = function (webpackEnv, argv) {
static: path.join(__dirname, PUBLIC_DIR),
port: DEVELOPMENT_PORT,
},
plugins: [
new BundleAnalyzerPlugin()
],
externals: externals
}
};

0 comments on commit b311d9d

Please sign in to comment.