2021-10-13 20:18:59 +08:00
|
|
|
const path = require('path');
|
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
2021-10-29 19:27:34 +08:00
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
2021-10-13 20:18:59 +08:00
|
|
|
const { ModuleFederationPlugin } = require('webpack').container;
|
|
|
|
const packageJson = require('./package.json');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
entry: './src/index',
|
2021-10-14 00:13:37 +08:00
|
|
|
// mode: 'production',
|
2021-10-13 20:18:59 +08:00
|
|
|
output: {
|
2021-10-13 23:07:28 +08:00
|
|
|
filename: `[name]_${packageJson.version}.js`,
|
2021-10-13 20:18:59 +08:00
|
|
|
chunkFilename: '[contenthash].js',
|
|
|
|
path: path.resolve(__dirname, 'dist/client'),
|
|
|
|
},
|
2021-10-14 00:13:37 +08:00
|
|
|
resolve: {
|
2021-10-27 18:18:27 +08:00
|
|
|
fallback: { crypto: false },
|
2021-10-14 00:13:37 +08:00
|
|
|
},
|
2021-10-13 20:18:59 +08:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
options: {
|
|
|
|
babelrc: false,
|
|
|
|
presets: ['@babel/preset-react'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'style-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'css-loader', // translates CSS into CommonJS
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
moduleIds: 'deterministic',
|
|
|
|
runtimeChunk: 'single',
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new CleanWebpackPlugin(),
|
2021-10-14 00:13:37 +08:00
|
|
|
// new webpack.DefinePlugin({
|
|
|
|
// 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
|
|
// }),
|
2021-10-13 20:18:59 +08:00
|
|
|
new ModuleFederationPlugin({
|
|
|
|
name: 'lowdefy_client',
|
|
|
|
shared: {
|
|
|
|
...packageJson.dependencies,
|
|
|
|
react: {
|
|
|
|
singleton: true, // only a single version of the shared module is allowed
|
|
|
|
requiredVersion: '~17.0.0',
|
|
|
|
version: packageJson.dependencies.react,
|
|
|
|
},
|
|
|
|
'react-dom': {
|
|
|
|
singleton: true, // only a single version of the shared module is allowed
|
|
|
|
requiredVersion: '~17.0.0',
|
|
|
|
version: packageJson.dependencies['react-dom'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2021-10-29 19:27:34 +08:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: './src/public',
|
|
|
|
to: '../public',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2021-10-13 20:18:59 +08:00
|
|
|
],
|
|
|
|
};
|