2020-05-23 17:13:45 +00:00
|
|
|
//
|
2020-06-23 14:19:01 +00:00
|
|
|
// Copyright 2019 DXOS.org
|
2020-05-23 17:13:45 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const Dotenv = require('dotenv-webpack');
|
2023-03-20 02:19:28 +00:00
|
|
|
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
|
2020-05-23 17:13:45 +00:00
|
|
|
const VersionFile = require('webpack-version-file-plugin');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
|
|
|
|
const PUBLIC_URL = process.env.PUBLIC_URL || '';
|
|
|
|
|
2020-07-20 20:20:36 +00:00
|
|
|
const CONFIG_FILE = path.relative('./src', process.env.CONFIG_FILE || 'config-local.yml');
|
2020-05-23 17:13:45 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
devtool: 'eval-source-map',
|
|
|
|
|
2023-03-20 01:11:48 +00:00
|
|
|
watchOptions: {
|
|
|
|
ignored: /node_modules/,
|
|
|
|
aggregateTimeout: 600
|
|
|
|
},
|
|
|
|
|
2020-05-23 17:13:45 +00:00
|
|
|
devServer: {
|
2023-03-20 01:11:48 +00:00
|
|
|
static: {
|
|
|
|
directory: path.join(__dirname, "dist")
|
|
|
|
},
|
2020-05-23 17:13:45 +00:00
|
|
|
compress: true,
|
2023-03-20 01:11:48 +00:00
|
|
|
allowedHosts: "all",
|
|
|
|
port: 8080
|
2020-05-23 17:13:45 +00:00
|
|
|
},
|
|
|
|
|
2023-03-20 01:11:48 +00:00
|
|
|
resolve: {
|
|
|
|
fallback: {
|
|
|
|
fs: false
|
|
|
|
}
|
2020-05-23 17:13:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
output: {
|
2020-05-23 18:36:15 +00:00
|
|
|
path: `${__dirname}/dist/production`,
|
2020-05-23 17:13:45 +00:00
|
|
|
filename: '[name].bundle.js',
|
|
|
|
publicPath: PUBLIC_URL
|
|
|
|
},
|
|
|
|
|
|
|
|
optimization: {
|
|
|
|
runtimeChunk: 'single',
|
|
|
|
splitChunks: {
|
|
|
|
chunks: 'all',
|
|
|
|
maxInitialRequests: Infinity,
|
|
|
|
minSize: 0,
|
|
|
|
cacheGroups: {
|
|
|
|
vendor: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
2020-05-23 23:01:17 +00:00
|
|
|
name (module) {
|
2020-05-23 17:13:45 +00:00
|
|
|
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
|
|
|
|
|
2022-12-05 08:46:14 +00:00
|
|
|
if (packageName.startsWith('@cerc-io')) {
|
|
|
|
return 'cerc-io';
|
2020-05-23 17:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (packageName.startsWith('@material-ui')) {
|
|
|
|
return 'material-ui';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'vendor';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
|
|
|
|
// https://www.npmjs.com/package/dotenv-webpack#properties
|
|
|
|
new Dotenv({
|
|
|
|
path: process.env.DOT_ENV || '.env'
|
|
|
|
}),
|
|
|
|
|
|
|
|
// NOTE: Must be defined below Dotenv (otherwise will override).
|
|
|
|
// https://webpack.js.org/plugins/environment-plugin
|
2020-05-31 18:38:44 +00:00
|
|
|
// new webpack.EnvironmentPlugin({}),
|
2020-05-23 17:13:45 +00:00
|
|
|
|
|
|
|
// Define the build config file based on the target.
|
|
|
|
// https://webpack.js.org/plugins/normal-module-replacement-plugin
|
2020-07-20 20:20:36 +00:00
|
|
|
new webpack.NormalModuleReplacementPlugin(/(.*)__CONFIG_FILE__/, (resource) => {
|
|
|
|
resource.request = resource.request.replace(/__CONFIG_FILE__/, CONFIG_FILE);
|
2020-05-23 17:13:45 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
// https://www.npmjs.com/package/webpack-version-file-plugin
|
|
|
|
new VersionFile({
|
2020-05-27 23:09:20 +00:00
|
|
|
template: path.join(__dirname, 'version.ejs'),
|
2020-05-23 17:13:45 +00:00
|
|
|
packageFile: path.join(__dirname, 'package.json'),
|
2020-05-27 23:09:20 +00:00
|
|
|
outputFile: path.join(__dirname, 'src', 'version.json')
|
2023-03-20 02:19:28 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
new NodePolyfillPlugin()
|
2020-05-23 17:13:45 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /(node_modules)/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader'
|
|
|
|
}
|
|
|
|
},
|
2020-05-24 02:37:52 +00:00
|
|
|
// https://github.com/eemeli/yaml-loader
|
|
|
|
{
|
|
|
|
test: /\.ya?ml$/,
|
|
|
|
use: 'yaml-loader'
|
2020-05-23 17:13:45 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2023-03-21 15:41:03 +00:00
|
|
|
|
2020-05-23 17:13:45 +00:00
|
|
|
};
|