Skip to content

Commit

Permalink
feat: update webpack config to build UMD types within webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Stärk committed Apr 9, 2024
1 parent fc83cfb commit cac8468
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"build": "run-s clear prettier build:*",
"build:main": "tsc -p tsconfig.json",
"build:module": "tsc -p tsconfig.esm.json",
"build:umd": "webpack --config webpack.config.js --mode=production && npm run generate:types",
"generate:types": "dts-bundle-generator --umd-module-name HybridFormsJS -o dist/umd/hybridforms.d.ts src/index.ts",
"build:umd": "webpack --config webpack.config.js --mode=production",
"postbuild": "cd dist && zip -r ../dist.zip * && cd umd && zip -r ../../dist-umd.zip *",
"clear": "rimraf dist/* && rimraf dist-umd.zip && rimraf dist.zip",
"prettier": "prettier src --write",
Expand All @@ -31,10 +30,10 @@
"@types/node": "^20.4.6",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"bundle-declarations-webpack-plugin": "^5.1.1",
"chai": "^4.3.7",
"chai-uuid": "^1.0.6",
"dotenv": "^16.3.1",
"dts-bundle-generator": "^8.1.2",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
Expand Down
29 changes: 22 additions & 7 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const webpack = require('webpack')
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin')
const webpack = require('webpack');
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const {
BundleDeclarationsWebpackPlugin
} = require('bundle-declarations-webpack-plugin');

const entry = './src/index.ts';

module.exports = {
entry: './src/index.ts',
entry,
output: {
path: path.resolve(__dirname, 'dist/umd'),
filename: 'hybridforms.min.js',
Expand All @@ -16,7 +21,7 @@ module.exports = {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
extractComments: false
})
]
},
Expand All @@ -32,7 +37,7 @@ module.exports = {
]
},
resolve: {
extensions: ['.ts', '.js', '.json'],
extensions: ['.ts', '.js', '.json']
},
externalsPresets: { node: true },
plugins: [
Expand All @@ -42,5 +47,15 @@ module.exports = {
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
}),
new BundleDeclarationsWebpackPlugin({
entry: {
filePath: entry,
output: {
umdModuleName: 'HybridFormsJS',
noBanner: true
}
},
outFile: 'hybridforms.d.ts'
})
]
}
};

0 comments on commit cac8468

Please sign in to comment.