build(core): single webpack config for all packages
MODIFY
package.json
package.json
"postinstall": "yarn build",
"build": "lerna link && lerna bootstrap --hoist",
"benchmark": "make -C benchmarks",
- "watch": "lerna run --parallel watch",
+ "watch": "lerna run --parallel --stream watch",
"lint": "tslint --config tslint.json --project tsconfig.spec.json",
"test": "jest --expand",
"test:coverage": "SCOPE=unit jest --expand --coverage",
"@types/mock-fs": "^3.6.30",
"@types/supertest": "^2.0.4",
"@types/webpack": "^4.4.11",
+ "@types/webpack-merge": "^4.1.3",
+ "@types/webpack-node-externals": "^1.6.3",
"husky": "^0.14.0",
"jest": "^23.5.0",
"lerna": "^2.11.0",

MODIFY
packages/core/webpack.config.ts
packages/core/webpack.config.ts
-import * as path from 'path';
-import * as webpack from 'webpack';
-import * as nodeExternals from 'webpack-node-externals';
+import * as merge from 'webpack-merge';
+import { getConfig } from '../../webpack.config';
-const config: webpack.Configuration = {
- entry: './src/index.ts',
- devtool: 'inline-source-map',
- target: 'node',
- resolve: {
- extensions: ['.tsx', '.ts', '.js', '.json'],
- modules: ['node_modules'],
- symlinks: false,
- },
- module: {
- rules: [
- {
- test: /\.tsx?$/,
- exclude: ['node_modules'],
- use: ['ts-loader'],
- }
- ]
- },
- output: {
- filename: 'index.js',
- path: path.resolve(__dirname, 'dist'),
- libraryTarget: 'commonjs2',
- },
- externals: [
- nodeExternals(),
- nodeExternals({
- modulesDir: path.resolve(__dirname, '../../node_modules')
- })],
- optimization: {
- minimize: false
- },
-};
-
-export default config;
+export default merge(getConfig(__dirname));

MODIFY
packages/middleware-body/package.json
packages/middleware-body/package.json
"types": "./dist/index.d.ts",
"scripts": {
"start": "yarn watch",
- "watch": "tsc -w",
- "build": "tsc",
+ "watch": "webpack -w",
+ "build": "webpack",
"prepack": "yarn build",
"prepare": "yarn build"
},

ADD
packages/middleware-body/webpack.config.ts
+import * as merge from 'webpack-merge';
+import { getConfig } from '../../webpack.config';
+
+export default merge(getConfig(__dirname));

MODIFY
packages/middleware-joi/package.json
packages/middleware-joi/package.json
"types": "./dist/index.d.ts",
"scripts": {
"start": "yarn watch",
- "watch": "tsc -w",
- "build": "tsc",
+ "watch": "webpack -w",
+ "build": "webpack",
"test": "jest --config ../../jest.config.js",
"prepack": "yarn build",
"prepare": "yarn build"

ADD
packages/middleware-joi/webpack.config.ts
+import * as merge from 'webpack-merge';
+import { getConfig } from '../../webpack.config';
+
+export default merge(getConfig(__dirname));

MODIFY
packages/middleware-logger/package.json
packages/middleware-logger/package.json
"types": "./dist/index.d.ts",
"scripts": {
"start": "yarn watch",
- "watch": "tsc -w",
- "build": "tsc",
+ "watch": "webpack -w",
+ "build": "webpack",
"prepack": "yarn build",
"prepare": "yarn build"
},

ADD
packages/middleware-logger/webpack.config.ts
+import * as merge from 'webpack-merge';
+import { getConfig } from '../../webpack.config';
+
+export default merge(getConfig(__dirname));

ADD
webpack.config.ts
+import * as path from 'path';
+import * as webpack from 'webpack';
+import * as nodeExternals from 'webpack-node-externals';
+
+export const getConfig = (base: string): webpack.Configuration => ({
+ entry: path.resolve(base, './src/index.ts'),
+ devtool: 'inline-source-map',
+ mode: 'production',
+ target: 'node',
+ resolve: {
+ extensions: ['.tsx', '.ts', '.js', '.json'],
+ modules: ['node_modules'],
+ symlinks: false,
+ },
+ module: {
+ rules: [{
+ test: /\.tsx?$/,
+ exclude: ['node_modules'],
+ use: ['ts-loader'],
+ sideEffects: false,
+ }]
+ },
+ output: {
+ filename: 'index.js',
+ path: path.resolve(base, 'dist'),
+ libraryTarget: 'commonjs2',
+ },
+ externals: [
+ nodeExternals(),
+ nodeExternals({
+ modulesDir: path.resolve(base, '../../node_modules')
+ }),
+ ],
+ stats: {
+ colors: true,
+ },
+});

MODIFY
yarn.lock
yarn.lock
dependencies:
source-map "^0.6.1"
-"@types/webpack@^4.4.11":
+"@types/webpack-merge@^4.1.3":
+ version "4.1.3"
+ resolved "https://registry.yarnpkg.com/@types/webpack-merge/-/webpack-merge-4.1.3.tgz#e6af0f2a0f20a86ac83d7da84a2e454063121ad4"
+ dependencies:
+ "@types/webpack" "*"
+
+"@types/webpack-node-externals@^1.6.3":
+ version "1.6.3"
+ resolved "https://registry.yarnpkg.com/@types/webpack-node-externals/-/webpack-node-externals-1.6.3.tgz#a70ecab38339ab219d0090680c98c4973a90af01"
+ dependencies:
+ "@types/webpack" "*"
+
+"@types/webpack@*", "@types/webpack@^4.4.11":
version "4.4.11"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.4.11.tgz#0ca832870d55c4e92498c01d22d00d02b0f62ae9"
dependencies:

build(core): single webpack config for all packages