forked from openmrs/openmrs-esm-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
75 lines (73 loc) · 2.17 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
70
71
72
73
74
75
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const { resolve, basename } = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { ModuleFederationPlugin } = require('webpack').container;
const { name, browser, main, peerDependencies } = require('./package.json');
/**
* @param {*} env
* @returns {import("webpack/types").Configuration}
*/
module.exports = (env) => ({
entry: [resolve(__dirname, 'src/index.ts')],
output: {
filename: 'openmrs-esm-framework.js',
path: resolve(__dirname, 'dist'),
library: { type: 'system' },
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.m?(js|ts|tsx)$/,
exclude: /node_modules/,
use: 'swc-loader',
},
{
test: /\.css$/,
use: [{ loader: require.resolve('style-loader') }, { loader: require.resolve('css-loader') }],
},
{
test: /\.scss$/,
use: [
{ loader: require.resolve('style-loader') },
{ loader: require.resolve('css-loader') },
{ loader: require.resolve('sass-loader') },
],
},
],
},
resolve: {
extensions: ['.ts', '.js', '.tsx', '.jsx', '.scss'],
},
plugins: [
new CleanWebpackPlugin(),
new ForkTsCheckerWebpackPlugin(),
new BundleAnalyzerPlugin({
analyzerMode: env && env.analyze ? 'static' : 'disabled',
}),
new ModuleFederationPlugin({
// See `esm-app-shell/src/load-modules.ts` for an explanation of how modules
// get loaded into the application.
name,
library: { type: 'var', name: '_openmrs_esm_framework' },
filename: basename(browser || main),
shared: [...Object.keys(peerDependencies)].reduce((obj, depName) => {
obj[depName] = {
requiredVersion: peerDependencies[depName] ?? false,
singleton: true,
import: depName,
shareKey: depName,
shareScope: 'default',
};
return obj;
}, {}),
}),
],
devServer: {
disableHostCheck: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
},
});