2019-10-15 14:52:23 -04:00
|
|
|
// ~~ ENV
|
|
|
|
|
const dotenv = require('dotenv');
|
|
|
|
|
//
|
2019-09-04 13:53:13 -04:00
|
|
|
const path = require('path');
|
2023-06-06 13:34:26 -04:00
|
|
|
const fs = require('fs');
|
|
|
|
|
|
2026-06-12 16:04:56 -04:00
|
|
|
const webpack = require('@rspack/core');
|
2022-04-06 13:28:42 -04:00
|
|
|
|
|
|
|
|
// ~~ PLUGINS
|
2024-06-19 09:32:00 -04:00
|
|
|
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
2022-04-06 13:28:42 -04:00
|
|
|
|
|
|
|
|
// ~~ PackageJSON
|
2022-07-27 16:39:04 +00:00
|
|
|
// const vtkRules = require('vtk.js/Utilities/config/dependency.js').webpack.core
|
|
|
|
|
// .rules;
|
2019-10-11 14:26:24 -04:00
|
|
|
// ~~ RULES
|
2024-08-15 14:36:53 -04:00
|
|
|
// const loadShadersRule = require('./rules/loadShaders.js');
|
2019-09-04 13:53:13 -04:00
|
|
|
const loadWebWorkersRule = require('./rules/loadWebWorkers.js');
|
|
|
|
|
const transpileJavaScriptRule = require('./rules/transpileJavaScript.js');
|
2021-07-26 13:22:25 +02:00
|
|
|
const cssToJavaScript = require('./rules/cssToJavaScript.js');
|
2026-06-12 16:04:56 -04:00
|
|
|
// Module-resolution rules shared with the rsbuild build (see rsbuild.config.ts).
|
|
|
|
|
const resolveConfig = require('./resolveConfig');
|
2024-08-15 14:36:53 -04:00
|
|
|
// Only uncomment for old v2 stylus
|
|
|
|
|
// const stylusToJavaScript = require('./rules/stylusToJavaScript.js');
|
2026-06-12 16:04:56 -04:00
|
|
|
let ReactRefreshWebpackPlugin;
|
|
|
|
|
try {
|
|
|
|
|
const mod = require('@rspack/plugin-react-refresh');
|
|
|
|
|
ReactRefreshWebpackPlugin = mod.ReactRefreshRspackPlugin || mod.default || mod;
|
|
|
|
|
} catch { ReactRefreshWebpackPlugin = null; }
|
2024-06-19 09:32:00 -04:00
|
|
|
|
2019-10-11 14:26:24 -04:00
|
|
|
// ~~ ENV VARS
|
|
|
|
|
const NODE_ENV = process.env.NODE_ENV;
|
|
|
|
|
const QUICK_BUILD = process.env.QUICK_BUILD;
|
2019-10-15 14:09:14 -03:00
|
|
|
const BUILD_NUM = process.env.CIRCLE_BUILD_NUM || '0';
|
2025-04-16 15:56:52 -04:00
|
|
|
const IS_COVERAGE = process.env.COVERAGE === 'true';
|
2019-09-04 13:53:13 -04:00
|
|
|
|
2023-06-06 13:34:26 -04:00
|
|
|
// read from ../version.txt
|
2023-09-01 16:19:39 -04:00
|
|
|
const VERSION_NUMBER = fs.readFileSync(path.join(__dirname, '../version.txt'), 'utf8') || '';
|
2023-06-06 13:34:26 -04:00
|
|
|
|
2023-09-01 16:19:39 -04:00
|
|
|
const COMMIT_HASH = fs.readFileSync(path.join(__dirname, '../commit.txt'), 'utf8') || '';
|
2023-06-06 13:34:26 -04:00
|
|
|
|
2019-10-15 14:52:23 -04:00
|
|
|
//
|
|
|
|
|
dotenv.config();
|
|
|
|
|
|
2023-10-03 10:59:09 -04:00
|
|
|
const defineValues = {
|
|
|
|
|
/* Application */
|
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
2023-10-05 23:39:56 -04:00
|
|
|
'process.env.NODE_DEBUG': JSON.stringify(process.env.NODE_DEBUG),
|
2023-10-03 10:59:09 -04:00
|
|
|
'process.env.DEBUG': JSON.stringify(process.env.DEBUG),
|
|
|
|
|
'process.env.PUBLIC_URL': JSON.stringify(process.env.PUBLIC_URL || '/'),
|
|
|
|
|
'process.env.BUILD_NUM': JSON.stringify(BUILD_NUM),
|
|
|
|
|
'process.env.VERSION_NUMBER': JSON.stringify(VERSION_NUMBER),
|
|
|
|
|
'process.env.COMMIT_HASH': JSON.stringify(COMMIT_HASH),
|
|
|
|
|
/* i18n */
|
|
|
|
|
'process.env.USE_LOCIZE': JSON.stringify(process.env.USE_LOCIZE || ''),
|
|
|
|
|
'process.env.LOCIZE_PROJECTID': JSON.stringify(process.env.LOCIZE_PROJECTID || ''),
|
|
|
|
|
'process.env.LOCIZE_API_KEY': JSON.stringify(process.env.LOCIZE_API_KEY || ''),
|
|
|
|
|
'process.env.REACT_APP_I18N_DEBUG': JSON.stringify(process.env.REACT_APP_I18N_DEBUG || ''),
|
2025-04-08 18:34:45 -04:00
|
|
|
'process.env.TEST_ENV': JSON.stringify(process.env.TEST_ENV || ''),
|
2023-10-03 10:59:09 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Only redefine updated values. This avoids warning messages in the logs
|
|
|
|
|
if (!process.env.APP_CONFIG) {
|
|
|
|
|
defineValues['process.env.APP_CONFIG'] = '';
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 13:34:26 -04:00
|
|
|
module.exports = (env, argv, { SRC_DIR, ENTRY }) => {
|
2019-10-11 14:26:24 -04:00
|
|
|
const mode = NODE_ENV === 'production' ? 'production' : 'development';
|
|
|
|
|
const isProdBuild = NODE_ENV === 'production';
|
|
|
|
|
const isQuickBuild = QUICK_BUILD === 'true';
|
2019-09-04 13:53:13 -04:00
|
|
|
|
2019-10-11 14:26:24 -04:00
|
|
|
const config = {
|
|
|
|
|
mode: isProdBuild ? 'production' : 'development',
|
2023-02-17 15:04:07 -05:00
|
|
|
devtool: isProdBuild ? 'source-map' : 'cheap-module-source-map',
|
2026-06-12 16:04:56 -04:00
|
|
|
// `rspack serve` (@rspack/cli) auto-enables lazyCompilation for web-only
|
|
|
|
|
// apps unless the config defines it explicitly. The on-demand proxy chunks
|
|
|
|
|
// it produces fail to load in the headless cypress/electron e2e run
|
|
|
|
|
// (ChunkLoadError on cornerstone vendor chunks), so disable it here to match
|
|
|
|
|
// the rsbuild build (see rsbuild.config.ts `dev.lazyCompilation: false`).
|
|
|
|
|
lazyCompilation: false,
|
2023-06-06 13:34:26 -04:00
|
|
|
entry: ENTRY,
|
2019-10-11 14:26:24 -04:00
|
|
|
optimization: {
|
2022-04-06 13:28:42 -04:00
|
|
|
// splitChunks: {
|
|
|
|
|
// // include all types of chunks
|
|
|
|
|
// chunks: 'all',
|
|
|
|
|
// },
|
2021-09-24 09:06:52 +02:00
|
|
|
//runtimeChunk: 'single',
|
2019-10-11 14:26:24 -04:00
|
|
|
minimize: isProdBuild,
|
2023-06-06 13:34:26 -04:00
|
|
|
sideEffects: false,
|
2019-10-11 14:26:24 -04:00
|
|
|
},
|
2021-09-24 09:06:52 +02:00
|
|
|
output: {
|
2022-04-06 13:28:42 -04:00
|
|
|
// clean: true,
|
2021-09-24 09:06:52 +02:00
|
|
|
publicPath: '/',
|
|
|
|
|
},
|
2019-09-04 13:53:13 -04:00
|
|
|
context: SRC_DIR,
|
2019-10-11 14:26:24 -04:00
|
|
|
stats: {
|
|
|
|
|
colors: true,
|
|
|
|
|
hash: true,
|
|
|
|
|
timings: true,
|
|
|
|
|
assets: true,
|
|
|
|
|
chunks: false,
|
|
|
|
|
chunkModules: false,
|
|
|
|
|
modules: false,
|
|
|
|
|
children: false,
|
|
|
|
|
warnings: true,
|
|
|
|
|
},
|
2026-06-12 16:04:56 -04:00
|
|
|
cache: isProdBuild ? false : { type: 'filesystem' },
|
2019-09-04 13:53:13 -04:00
|
|
|
module: {
|
2024-11-06 11:16:43 -05:00
|
|
|
noParse: [/(dicomicc)/],
|
2019-09-04 13:53:13 -04:00
|
|
|
rules: [
|
2024-10-15 09:53:26 -04:00
|
|
|
...(isProdBuild
|
|
|
|
|
? []
|
|
|
|
|
: [
|
2025-04-16 15:56:52 -04:00
|
|
|
...(IS_COVERAGE
|
|
|
|
|
? [
|
|
|
|
|
{
|
|
|
|
|
test: /\.[jt]sx?$/,
|
|
|
|
|
exclude: /node_modules/,
|
|
|
|
|
use: {
|
|
|
|
|
loader: 'babel-loader',
|
|
|
|
|
options: {
|
|
|
|
|
presets: ['@babel/preset-typescript', '@babel/preset-react'],
|
|
|
|
|
plugins: ['istanbul'],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
: [
|
|
|
|
|
{
|
|
|
|
|
test: /\.[jt]sx?$/,
|
|
|
|
|
exclude: /node_modules/,
|
|
|
|
|
loader: 'babel-loader',
|
|
|
|
|
options: {
|
|
|
|
|
plugins: isProdBuild ? [] : ['react-refresh/babel'],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]),
|
2024-10-15 09:53:26 -04:00
|
|
|
]),
|
2024-05-27 14:30:25 -04:00
|
|
|
{
|
|
|
|
|
test: /\.svg?$/,
|
|
|
|
|
oneOf: [
|
|
|
|
|
{
|
|
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: '@svgr/webpack',
|
|
|
|
|
options: {
|
|
|
|
|
svgoConfig: {
|
|
|
|
|
plugins: [
|
|
|
|
|
{
|
|
|
|
|
name: 'preset-default',
|
|
|
|
|
params: {
|
|
|
|
|
overrides: {
|
2024-10-15 09:53:26 -04:00
|
|
|
removeViewBox: false,
|
2024-05-27 14:30:25 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-10-15 09:53:26 -04:00
|
|
|
],
|
2024-05-27 14:30:25 -04:00
|
|
|
},
|
|
|
|
|
prettier: false,
|
|
|
|
|
svgo: true,
|
|
|
|
|
titleProp: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
issuer: {
|
|
|
|
|
and: [/\.(ts|tsx|js|jsx|md|mdx)$/],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2019-09-04 13:53:13 -04:00
|
|
|
transpileJavaScriptRule(mode),
|
|
|
|
|
loadWebWorkersRule,
|
2022-07-27 16:39:04 +00:00
|
|
|
// loadShadersRule,
|
2021-07-08 15:23:09 +02:00
|
|
|
{
|
|
|
|
|
test: /\.m?js/,
|
|
|
|
|
resolve: {
|
|
|
|
|
fullySpecified: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-07-26 13:22:25 +02:00
|
|
|
cssToJavaScript,
|
2023-04-27 20:53:52 -04:00
|
|
|
{
|
|
|
|
|
test: /\.wasm/,
|
|
|
|
|
type: 'asset/resource',
|
|
|
|
|
},
|
2024-04-02 09:35:30 -04:00
|
|
|
{
|
|
|
|
|
test: /\.(png|jpe?g|gif|svg)$/i,
|
|
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'file-loader',
|
|
|
|
|
options: {
|
|
|
|
|
name: 'assets/images/[name].[ext]',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2025-03-11 09:50:46 -04:00
|
|
|
{
|
|
|
|
|
test: /\.(woff|woff2|eot|ttf|otf)$/i,
|
|
|
|
|
type: 'asset/resource',
|
|
|
|
|
},
|
2022-07-27 16:39:04 +00:00
|
|
|
], //.concat(vtkRules),
|
2019-09-04 13:53:13 -04:00
|
|
|
},
|
|
|
|
|
resolve: {
|
2021-09-24 09:06:52 +02:00
|
|
|
mainFields: ['module', 'browser', 'main'],
|
2026-06-12 16:04:56 -04:00
|
|
|
// alias and modules are shared with the rsbuild build via ./resolveConfig
|
|
|
|
|
// so the two pipelines resolve identically.
|
2020-05-17 23:27:04 -04:00
|
|
|
alias: {
|
2026-06-12 16:04:56 -04:00
|
|
|
...resolveConfig.alias,
|
2020-05-17 23:27:04 -04:00
|
|
|
},
|
2026-06-12 16:04:56 -04:00
|
|
|
modules: resolveConfig.getModules(SRC_DIR),
|
2019-09-04 13:53:13 -04:00
|
|
|
// Attempt to resolve these extensions in order.
|
2022-07-27 16:39:04 +00:00
|
|
|
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx', '*'],
|
2026-06-12 16:04:56 -04:00
|
|
|
// Workspace packages use relative imports between sibling packages.
|
|
|
|
|
// Resolve symlinks to keep those imports anchored at the real package paths.
|
2019-09-04 13:53:13 -04:00
|
|
|
symlinks: true,
|
2023-08-29 11:20:01 -04:00
|
|
|
fallback: {
|
|
|
|
|
fs: false,
|
|
|
|
|
path: false,
|
|
|
|
|
zlib: false,
|
2023-09-01 16:19:39 -04:00
|
|
|
buffer: require.resolve('buffer'),
|
2023-08-29 11:20:01 -04:00
|
|
|
},
|
2019-09-04 13:53:13 -04:00
|
|
|
},
|
2026-06-12 16:04:56 -04:00
|
|
|
node: {
|
|
|
|
|
// Leave __filename / __dirname references alone. The previous 'mock'
|
|
|
|
|
// value triggers an rspack warning whenever bundled deps reference
|
|
|
|
|
// __dirname (e.g. Emscripten-compiled cornerstone codecs). Those refs
|
|
|
|
|
// sit inside `if (ENVIRONMENT_IS_NODE)` branches that never execute in
|
|
|
|
|
// the browser, so leaving them un-substituted is harmless at runtime.
|
|
|
|
|
__filename: false,
|
|
|
|
|
__dirname: false,
|
|
|
|
|
},
|
2019-09-04 13:53:13 -04:00
|
|
|
plugins: [
|
2023-10-03 10:59:09 -04:00
|
|
|
new webpack.DefinePlugin(defineValues),
|
2023-08-29 11:20:01 -04:00
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
|
Buffer: ['buffer', 'Buffer'],
|
|
|
|
|
}),
|
2026-06-12 16:04:56 -04:00
|
|
|
new webpack.IgnorePlugin({
|
|
|
|
|
resourceRegExp: /^(fs|path)$/,
|
|
|
|
|
contextRegExp: /@cornerstonejs[\\/]codec-/,
|
|
|
|
|
}),
|
|
|
|
|
...(isProdBuild || IS_COVERAGE || !ReactRefreshWebpackPlugin
|
|
|
|
|
? []
|
|
|
|
|
: [new ReactRefreshWebpackPlugin({ overlay: false })]),
|
2021-07-13 23:48:16 +02:00
|
|
|
// Uncomment to generate bundle analyzer
|
|
|
|
|
// new BundleAnalyzerPlugin(),
|
2019-09-04 13:53:13 -04:00
|
|
|
],
|
|
|
|
|
};
|
2019-10-11 14:26:24 -04:00
|
|
|
|
|
|
|
|
if (isProdBuild) {
|
2026-06-12 16:04:56 -04:00
|
|
|
config.optimization.minimizer = [new webpack.SwcJsMinimizerRspackPlugin()];
|
2019-10-11 14:26:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isQuickBuild) {
|
|
|
|
|
config.optimization.minimize = false;
|
|
|
|
|
config.devtool = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return config;
|
2019-09-04 13:53:13 -04:00
|
|
|
};
|