2020-10-28 21:21:14 +08:00
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
2020-10-02 23:25:51 +08:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const { ModuleFederationPlugin } = require('webpack').container;
|
2020-10-12 23:38:40 +08:00
|
|
|
const webpack = require('webpack');
|
2020-10-02 23:25:51 +08:00
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const deps = require('./package.json').dependencies;
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
entry: './src/index',
|
2020-10-09 22:58:51 +08:00
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, 'dist'),
|
|
|
|
},
|
2020-10-12 23:38:40 +08:00
|
|
|
// webpack 5 support polyfills
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
buffer: require.resolve('buffer'),
|
|
|
|
},
|
|
|
|
fallback: { buffer: false },
|
|
|
|
},
|
2020-10-02 23:25:51 +08:00
|
|
|
module: {
|
|
|
|
rules: [
|
2020-10-12 23:38:40 +08:00
|
|
|
// TODO: FIXME: do NOT webpack 5 support with this
|
|
|
|
// x-ref: https://github.com/webpack/webpack/issues/11467
|
|
|
|
// waiting for babel fix: https://github.com/vercel/next.js/pull/17095#issuecomment-692435147
|
|
|
|
{
|
|
|
|
test: /\.m?js/,
|
|
|
|
resolve: {
|
|
|
|
fullySpecified: false,
|
|
|
|
},
|
|
|
|
},
|
2020-10-02 23:25:51 +08:00
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
options: {
|
|
|
|
presets: ['@babel/preset-react'],
|
|
|
|
},
|
|
|
|
},
|
2020-10-09 22:58:51 +08:00
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'style-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'css-loader', // translates CSS into CommonJS
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-10-02 23:25:51 +08:00
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
2020-10-28 21:21:14 +08:00
|
|
|
new CleanWebpackPlugin(),
|
2020-10-02 23:25:51 +08:00
|
|
|
new ModuleFederationPlugin({
|
2020-10-06 22:32:32 +08:00
|
|
|
name: 'lowdefy_renderer',
|
|
|
|
library: { type: 'var', name: 'lowdefy_renderer' },
|
2020-10-05 19:34:49 +08:00
|
|
|
filename: 'remoteEntry.js',
|
|
|
|
exposes: {
|
2020-10-09 22:58:51 +08:00
|
|
|
'./Renderer': './src/Renderer',
|
2020-10-05 19:34:49 +08:00
|
|
|
},
|
2020-10-02 23:25:51 +08:00
|
|
|
shared: {
|
|
|
|
...deps,
|
|
|
|
react: {
|
|
|
|
singleton: true, // only a single version of the shared module is allowed
|
2020-10-26 19:51:56 +08:00
|
|
|
requiredVersion: '~17.0.0',
|
|
|
|
version: deps.react,
|
2020-10-02 23:25:51 +08:00
|
|
|
},
|
|
|
|
'react-dom': {
|
|
|
|
singleton: true, // only a single version of the shared module is allowed
|
2020-10-26 19:51:56 +08:00
|
|
|
requiredVersion: '~17.0.0',
|
|
|
|
version: deps['react-dom'],
|
2020-10-02 23:25:51 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2020-10-12 23:38:40 +08:00
|
|
|
new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
|
2020-10-02 23:25:51 +08:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: './public/index.html',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|