-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
121 lines (119 loc) · 3.93 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const { ModuleFederationPlugin } = require('webpack').container;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const SungeroRemoteComponentMetadataPlugin = require('@directum/sungero-remote-component-metadata-plugin')
const { dependencies } = require('./package.json');
const manifest = require('./component.manifest');
module.exports = (env, argv) => {
const devMode = argv.mode === 'development';
const standaloneMode = env.mode === 'standalone';
const generateMetadataPlugin = new SungeroRemoteComponentMetadataPlugin(manifest);
const publicName = generateMetadataPlugin.getPublicName();
return {
entry: {
index: './index.js',
[publicName]: './public-path.js'
},
devtool: devMode ? 'eval-source-map' : 'nosources-source-map',
output: {
publicPath: '',
clean: true,
filename: devMode ? `[name]_${manifest.componentVersion}.js` : `[name]_${manifest.componentVersion}_[chunkhash:8].js`,
chunkFilename: devMode ? `chunks/[name]_${manifest.componentVersion}.js` : `chunks/[name]_${manifest.componentVersion}_[chunkhash:8].js`,
},
resolve: {
modules: [ 'etc', 'src', 'node_modules' ],
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
{
test: /\.(jpg|png|gif|jpeg)$/,
loader: 'url-loader',
},
{
test: /\.css$/,
use: [
{ loader: standaloneMode ? 'style-loader' : MiniCssExtractPlugin.loader },
{ loader: 'css-loader' }
],
},
{
test: /\.tsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: ['@babel/preset-react', '@babel/preset-typescript'],
}
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/,
type: 'asset/resource',
generator: {
filename: function(file) {
return `images/[name]_${manifest.componentVersion}.[ext]`;
}
}
}
]
},
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
mangle: true,
format: {
comments: false
}
},
exclude: [ /\.min\.js$/gi ] // skip pre-minified libs
}),
new CssMinimizerPlugin({
minimizerOptions: {
preset: [
'default',
{
discardComments: { removeAll: true },
colormin: false
},
],
},
})
]
},
plugins: standaloneMode ? [ new HtmlWebpackPlugin({ template: './index.html' }) ] :
[
new MiniCssExtractPlugin({
filename: devMode ? 'css/[name].css' : 'css/[name].[contenthash:8].css',
// Убрать insert, если требуется поднять приоритет стилей стороннего контрола над стилями веб клиента.
insert: linkTag => document.head.prepend(linkTag)
}),
new ModuleFederationPlugin({
name: publicName,
filename: 'remoteEntry.js',
exposes: {
loaders: './component.loaders.ts',
publicPath: './public-path.js'
},
shared: {
//...deps,
react: {
requiredVersion: dependencies.react
},
'react-dom': {
requiredVersion: dependencies['react-dom']
},
i18next: {
eager: false,
singleton: true,
requiredVersion: dependencies.i18next
}
},
}),
generateMetadataPlugin
]
}
}