From 3488632d4059ff718937f0ec881452a8e3fb1f04 Mon Sep 17 00:00:00 2001 From: Martin Albert Date: Thu, 31 Oct 2024 08:18:32 +0100 Subject: [PATCH] feat: update builds to include dev builds --- package.json | 4 +-- webpack.config.js | 80 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 718070a..3f95b61 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,9 @@ "node": ">=18.17.1" }, "scripts": { - "build": "webpack", + "build": "webpack --env production", + "build-dev": "webpack --env development", "run-dev": "cd tests && python3 -m http.server", - "build-dev": "webpack && uglifyjs ./dist/butter.js -c -m -o ./tests/lib/butter.min.js", "test": "npm run build && npm run test:all", "test:all": "npm run jest", "test:watch": "npm run jest --watch", diff --git a/webpack.config.js b/webpack.config.js index d6d195b..f33ca7e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,13 +1,12 @@ -import * as url from 'url'; +import * as url from "url"; import path from "path"; import webpack from "webpack"; import TerserPlugin from "terser-webpack-plugin"; +const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); -const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); - -const commonConfig = { - devtool: 'source-map', // Enable source maps +const productionConfig = { + mode: "production", optimization: { minimize: true, minimizer: [ @@ -15,48 +14,83 @@ const commonConfig = { terserOptions: { compress: true, mangle: true, - sourceMap: true, }, + extractComments: false }), ], }, plugins: [ new webpack.optimize.LimitChunkCountPlugin({ - maxChunks: 1 - }) + maxChunks: 1, + }), ], -} +}; + +const developmentConfig = { + mode: "development", + devtool: 'inline-source-map', + optimization: { + minimize: false, // No minification in development + }, +}; export default [ // UMD Build { - entry: './lib/butter.js', - mode: "production", + ...productionConfig, + entry: "./lib/butter.js", output: { - filename: 'butter.umd.js', + filename: "butter.umd.js", globalObject: "this", library: { - name: 'Butter', - type: 'umd', + name: "Butter", + type: "umd", }, - path: path.resolve(__dirname, 'dist') + path: path.resolve(__dirname, "dist"), }, - ...commonConfig }, // ES Module Build { - entry: './lib/butter.js', - mode: "production", + ...productionConfig, + entry: "./lib/butter.js", output: { - filename: 'butter.esm.js', + filename: "butter.esm.js", library: { - type: 'module' + type: "module", }, - path: path.resolve(__dirname, 'dist') + path: path.resolve(__dirname, "dist"), }, experiments: { outputModule: true, }, - ...commonConfig - } + }, + // UMD Build - Development + { + ...developmentConfig, + entry: "./lib/butter.js", + output: { + filename: "butter.umd.dev.js", + globalObject: "this", + library: { + name: "Butter", + type: "umd", + }, + path: path.resolve(__dirname, "dist"), + }, + }, + // ES Module Build - Development + { + ...developmentConfig, + entry: "./lib/butter.js", + output: { + filename: "butter.esm.dev.js", + library: { + type: "module", + }, + path: path.resolve(__dirname, "dist"), + }, + experiments: { + outputModule: true, + }, + }, ];