laconic-console/webpack-common.config.js

116 lines
2.6 KiB
JavaScript
Raw Normal View History

//
2020-06-23 14:19:01 +00:00
// Copyright 2019 DXOS.org
//
const path = require('path');
const Dotenv = require('dotenv-webpack');
2023-03-20 02:19:28 +00:00
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
const VersionFile = require('webpack-version-file-plugin');
const webpack = require('webpack');
const PUBLIC_URL = process.env.PUBLIC_URL || '';
const CONFIG_FILE = path.relative('./src', process.env.CONFIG_FILE || 'config-local.yml');
module.exports = {
devtool: 'eval-source-map',
2023-03-20 01:11:48 +00:00
watchOptions: {
ignored: /node_modules/,
aggregateTimeout: 600
},
devServer: {
2023-03-20 01:11:48 +00:00
static: {
directory: path.join(__dirname, "dist")
},
compress: true,
2023-03-20 01:11:48 +00:00
allowedHosts: "all",
port: 8080
},
2023-03-20 01:11:48 +00:00
resolve: {
fallback: {
fs: false
}
},
output: {
2020-05-23 18:36:15 +00:00
path: `${__dirname}/dist/production`,
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) {
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
if (packageName.startsWith('@cerc-io')) {
return 'cerc-io';
}
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({}),
// Define the build config file based on the target.
// https://webpack.js.org/plugins/normal-module-replacement-plugin
new webpack.NormalModuleReplacementPlugin(/(.*)__CONFIG_FILE__/, (resource) => {
resource.request = resource.request.replace(/__CONFIG_FILE__/, CONFIG_FILE);
}),
// https://www.npmjs.com/package/webpack-version-file-plugin
new VersionFile({
template: path.join(__dirname, 'version.ejs'),
packageFile: path.join(__dirname, 'package.json'),
outputFile: path.join(__dirname, 'src', 'version.json')
2023-03-20 02:19:28 +00:00
}),
new NodePolyfillPlugin()
],
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'
}
]
}
};