Skip to content

Commit

Permalink
fix: split production builds
Browse files Browse the repository at this point in the history
  • Loading branch information
martinalbert committed Oct 31, 2024
1 parent 88734fd commit 1205812
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 15 deletions.
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=18.17.1"
},
"scripts": {
"build": "webpack && uglifyjs ./dist/butter.js -c -m -o ./dist/butter.min.js",
"build": "webpack",
"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",
Expand All @@ -27,13 +27,25 @@
"type": "git",
"url": "git://github.com/buttercms/buttercms-js.git"
},
"main": "dist/butter.min.js",
"main": "dist/butter.umd.js",
"module": "dist/butter.esm.js",
"types": "lib/butter.d.ts",
"type": "module",
"exports": {
".": {
"import": "./dist/butter.esm.js",
"require": "./dist/butter.umd.js"
}
},
"files": [
"dist",
"lib/butter.d.ts"
],
"license": "MIT",
"devDependencies": {
"jest": "^29.7.0",
"msw": "^2.0.11",
"terser-webpack-plugin": "^5.3.10",
"uglify-js": "^3.17.4",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
Expand Down
65 changes: 52 additions & 13 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,62 @@
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));

export default {
entry: './lib/butter.js',
mode: "production",
output: {
filename: 'butter.js',
globalObject: "this",
library: 'Butter',
libraryTarget: 'umd',
libraryExport: 'default',
path: path.resolve(__dirname, 'dist')
const commonConfig = {
devtool: 'source-map', // Enable source maps
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: true,
mangle: true,
sourceMap: true,
},
}),
],
},
plugins: [
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
maxChunks: 1
})
]
};
],
}

export default [
// UMD Build
{
entry: './lib/butter.js',
mode: "production",
output: {
filename: 'butter.umd.js',
globalObject: "this",
library: {
name: 'Butter',
type: 'umd',
},
path: path.resolve(__dirname, 'dist')
},
...commonConfig
},
// ES Module Build
{
entry: './lib/butter.js',
mode: "production",
output: {
filename: 'butter.esm.js',
library: {
type: 'module'
},
path: path.resolve(__dirname, 'dist')
},
experiments: {
outputModule: true,
},
...commonConfig
}
];

0 comments on commit 1205812

Please sign in to comment.