Skip to content

Commit

Permalink
fix: better webpack bundling & types
Browse files Browse the repository at this point in the history
  • Loading branch information
hoonoh committed Dec 7, 2021
1 parent 0fe628e commit 985a258
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ rules:
overrides:
- files:
- test/*.js
- webpack.config.js
- webpack.config*.js
rules:
'@typescript-eslint/explicit-function-return-type': 0
'@typescript-eslint/no-var-requires': 0
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
dist
junit.xml
node_modules
types
webpack-status.json
coverage
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@
"packageManager": "[email protected]",
"bin": "bin/aws-spot-price",
"main": "dist/module.js",
"types": "types/module.d.ts",
"types": "dist/module.d.ts",
"license": "MIT",
"scripts": {
"prepublishOnly": "yarn clean && yarn build && yarn types",
"prepublishOnly": "yarn clean && yarn build && yarn build:types",
"prepare": "husky install",
"clean": "rm -rf dist && rm -rf types && rm -rf coverage",
"clean": "rm -rf dist && rm -rf coverage",
"build:ec2-info": "ts-node -T scripts/generate-ec2-info.ts",
"build:ec2-types": "ts-node -T scripts/generate-ec2-types.ts",
"build:regions": "ts-node -T scripts/generate-regions.ts",
"build:types": "tsc -p tsconfig.build-types.json",
"build": "webpack",
"build:analyze": "yarn build --profile --json > webpack-status.json && yarn dlx webpack-bundle-analyzer webpack-status.json",
"build:types": "dts-bundle-generator -o dist/module.d.ts src/module.ts",
"build": "webpack && webpack -c ./webpack.config-cli.js",
"changelog": "conventional-changelog -i CHANGELOG.md -s -p angular",
"test": "jest --runInBand --verbose",
"test:coverage": "yarn test --coverage",
Expand Down Expand Up @@ -64,6 +63,7 @@
"commitizen": "4.2.4",
"conventional-changelog-cli": "2.1.1",
"cz-conventional-changelog": "3.3.0",
"dts-bundle-generator": "6.2.0",
"eslint": "8.3.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "16.0.0",
Expand All @@ -72,7 +72,7 @@
"eslint-plugin-import": "2.25.3",
"eslint-plugin-jest": "25.3.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"eslint-plugin-unused-imports": "2.0.0",
"husky": "7.0.4",
"jest": "27.3.1",
Expand Down
22 changes: 0 additions & 22 deletions tsconfig.build-types.json

This file was deleted.

48 changes: 48 additions & 0 deletions webpack.config-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const path = require('path');

module.exports = {
mode: 'production',
entry: {
cli: path.resolve(__dirname, 'src/cli.ts'),
},
resolve: {
extensions: ['.js', '.json', '.ts', '.cjs', '.mjs'],
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, 'dist'),
},
ignoreWarnings: [
{
module: /node_modules\/yargs/,
},
],
target: 'node',
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
],
},
externalsPresets: {
node: true,
},
externals: [
{
'./module': 'commonjs ./module',
'aws-sdk': 'commonjs ./module.vendor',
'aws-sdk/clients/ec2': 'commonjs ./module.vendor',
'aws-sdk/lib/error': 'commonjs ./module.vendor',
'aws-sdk/lib/request': 'commonjs ./module.vendor',
},
],
};
24 changes: 15 additions & 9 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,20 @@ const path = require('path');
module.exports = {
mode: 'production',
entry: {
cli: path.resolve(__dirname, 'src/cli.ts'),
module: path.resolve(__dirname, 'src/module.ts'),
},
resolve: {
extensions: ['.js', '.json', '.ts', '.cjs', '.mjs'],
mainFields: ['main'], // yargs build fix
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, 'dist'),
},
ignoreWarnings: [
{
module: /node_modules\/yargs/,
},
],
target: 'node',
module: {
rules: [
{
test: /\.tsx?$/,
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
Expand All @@ -35,5 +28,18 @@ module.exports = {
},
],
},
externals: [/\.\/module$/],
optimization: {
chunkIds: 'named',
splitChunks: {
chunks: 'all',
minSize: 0,
cacheGroups: {
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
reuseExistingChunk: true,
filename: 'module.vendor.js',
},
},
},
},
};
43 changes: 39 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2708,6 +2708,7 @@ __metadata:
commitizen: 4.2.4
conventional-changelog-cli: 2.1.1
cz-conventional-changelog: 3.3.0
dts-bundle-generator: 6.2.0
eslint: 8.3.0
eslint-config-airbnb-base: 15.0.0
eslint-config-airbnb-typescript: 16.0.0
Expand All @@ -2716,7 +2717,7 @@ __metadata:
eslint-plugin-import: 2.25.3
eslint-plugin-jest: 25.3.0
eslint-plugin-prettier: 4.0.0
eslint-plugin-simple-import-sort: ^7.0.0
eslint-plugin-simple-import-sort: 7.0.0
eslint-plugin-unused-imports: 2.0.0
husky: 7.0.4
jest: 27.3.1
Expand Down Expand Up @@ -4308,6 +4309,18 @@ __metadata:
languageName: node
linkType: hard

"dts-bundle-generator@npm:6.2.0":
version: 6.2.0
resolution: "dts-bundle-generator@npm:6.2.0"
dependencies:
typescript: ">=3.0.1"
yargs: ^17.2.1
bin:
dts-bundle-generator: dist/bin/dts-bundle-generator.js
checksum: fc380c1e57a19eac2702e576aca8a8332330ebc92ef5b3bfa44ecd244e742bcf669709349b829f3fcd494e67bebae87e79ba87bca5afe84b18095d8133d32e82
languageName: node
linkType: hard

"duplexer2@npm:~0.1.0":
version: 0.1.4
resolution: "duplexer2@npm:0.1.4"
Expand Down Expand Up @@ -4677,7 +4690,7 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-simple-import-sort@npm:^7.0.0":
"eslint-plugin-simple-import-sort@npm:7.0.0":
version: 7.0.0
resolution: "eslint-plugin-simple-import-sort@npm:7.0.0"
peerDependencies:
Expand Down Expand Up @@ -11438,7 +11451,7 @@ typescript@^4.4.3:
languageName: node
linkType: hard

"typescript@npm:4.5.2":
"typescript@npm:4.5.2, typescript@npm:>=3.0.1":
version: 4.5.2
resolution: "typescript@npm:4.5.2"
bin:
Expand All @@ -11448,7 +11461,7 @@ typescript@^4.4.3:
languageName: node
linkType: hard

"typescript@patch:[email protected]#~builtin<compat/typescript>":
"typescript@patch:[email protected]#~builtin<compat/typescript>, typescript@patch:typescript@>=3.0.1#~builtin<compat/typescript>":
version: 4.5.2
resolution: "typescript@patch:typescript@npm%3A4.5.2#~builtin<compat/typescript>::version=4.5.2&hash=493e53"
bin:
Expand Down Expand Up @@ -12052,6 +12065,13 @@ typescript@^4.4.3:
languageName: node
linkType: hard

"yargs-parser@npm:^21.0.0":
version: 21.0.0
resolution: "yargs-parser@npm:21.0.0"
checksum: 1e205fca1cb7a36a1585e2b94a64e641c12741b53627d338e12747f4dca3c3610cdd9bb235040621120548dd74c3ef03a8168d52a1eabfedccbe4a62462b6731
languageName: node
linkType: hard

"yargs@npm:17.2.1":
version: 17.2.1
resolution: "yargs@npm:17.2.1"
Expand Down Expand Up @@ -12097,6 +12117,21 @@ typescript@^4.4.3:
languageName: node
linkType: hard

"yargs@npm:^17.2.1":
version: 17.3.0
resolution: "yargs@npm:17.3.0"
dependencies:
cliui: ^7.0.2
escalade: ^3.1.1
get-caller-file: ^2.0.5
require-directory: ^2.1.1
string-width: ^4.2.3
y18n: ^5.0.5
yargs-parser: ^21.0.0
checksum: 2b687338684bf9645e9389ffdbe813fc5a2ddfede299d46fbe5ac80eb9a391e558b97861ba44d2256936ebe9d7f8135f6a38af1c76a5685eac4061008b2df57a
languageName: node
linkType: hard

"yn@npm:3.1.1":
version: 3.1.1
resolution: "yn@npm:3.1.1"
Expand Down

0 comments on commit 985a258

Please sign in to comment.