-
Notifications
You must be signed in to change notification settings - Fork 15
/
webpack.config.js
69 lines (65 loc) · 1.86 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require('dotenv').config()
const path = require('path')
const chalk = require('chalk')
const { ModuleFederationPlugin } = require('webpack').container
const nodeExternals = require('webpack-node-externals')
const fetchRemotes = require('./webpack/fetch-remotes')
let remoteEntries = require('./webpack/remote-entries')
const server = env => {
handleEnv(env)
exitAfterBuild()
return new Promise(resolve => {
fetchRemotes(remoteEntries).then(remotes => {
console.info(remotes)
resolve({
externals: [nodeExternals(), 'mongodb-client-encryption'],
target: 'async-node',
//stats: 'verbose',
mode: 'development',
devtool: 'hidden-source-map',
entry: path.resolve(__dirname, 'src/bootstrap.js'),
output: {
publicPath: `http://localhost`,
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'commonjs',
filename: '[name].js'
},
resolve: {
extensions: ['.js', '.mjs', '.cjs', '.jsx']
},
module: {
rules: [
{
test: /\.js?$/,
loader: 'babel-loader',
exclude: /node_modules/
}
]
},
plugins: [
new ModuleFederationPlugin({
name: 'hostContainer',
filename: 'remoteEntry.js',
library: { type: 'commonjs' },
remotes,
exposes: {
'./hostContainer': './src/host-container.js',
'./remoteEntries': './webpack/remote-entries'
}
})
]
})
})
})
}
function handleEnv (env) {
console.log(env)
if (env.serverless) {
remoteEntries.forEach(e => (e.path = 'webpack'))
console.log(chalk.yellow('serverless build'))
}
}
function exitAfterBuild () {
setTimeout(() => process.exit(0), 4000)
}
module.exports = [server]