Created
January 21, 2018 17:37
-
-
Save impankratov/da930b50d5887f096bbf117660660445 to your computer and use it in GitHub Desktop.
Microservices multi-config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Somewhere in microservice folder | |
// Can be used to create a bundle for this specific microservice | |
import { resolve } from 'path'; | |
import * as webpack from 'webpack'; | |
import config, { Env } from '../../webpack.config'; | |
export default (env: Env = {}): webpack.Configuration => { | |
env.BUNDLE_FOLDER = resolve(__dirname, 'bin'); | |
const localConfig: webpack.Configuration = { | |
// Override all entries of the root configuration | |
// with single entry of current microservice | |
entry: { | |
cache: './src/cache/index.ts' | |
} | |
}; | |
return { ...config(env), ...localConfig }; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Main config, at the root of the project | |
// Used to generate bundles for each of the microservice | |
import * as CleanWebpackPlugin from 'clean-webpack-plugin'; | |
import { resolve } from 'path'; | |
import * as webpack from 'webpack'; | |
export interface Env { | |
NODE_ENV?: string; | |
BUNDLE_FOLDER?: string; | |
} | |
export default ({ | |
NODE_ENV = 'dev', | |
BUNDLE_FOLDER = resolve(__dirname, 'bin') | |
}: Env = {}): webpack.Configuration => { | |
const TS_CONFIG_FILE = `tsconfig.${NODE_ENV}.json`; | |
const defaultConfig: webpack.Configuration = { | |
entry: { | |
// Add microservices here | |
api: './src/api/index.ts', | |
cache: './src/cache/index.ts' | |
}, | |
plugins: [ | |
new CleanWebpackPlugin([BUNDLE_FOLDER]) | |
], | |
output: { | |
libraryTarget: 'commonjs', | |
path: BUNDLE_FOLDER, | |
filename: '[name]/bundle.js' | |
} | |
}; | |
return defaultConfig; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment