burdy
Version:
Open Source Headless Platform
204 lines (203 loc) • 8.24 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const webpack_1 = __importDefault(require("webpack"));
const webpackbar_1 = __importDefault(require("webpackbar"));
const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
const path_util_1 = __importDefault(require("../scripts/util/path.util"));
const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
const friendly_errors_webpack_plugin_1 = __importDefault(require("@soda/friendly-errors-webpack-plugin"));
const notifier_util_1 = require("../scripts/util/notifier.util");
const env_util_1 = require("../scripts/util/env.util");
const isProduction = process.env.NODE_ENV === 'production' || false;
const isDevelopment = !isProduction;
const ShowErrorsPlugin = new friendly_errors_webpack_plugin_1.default({
onErrors: (severity, errors) => {
if (severity !== 'error') {
return;
}
const [error] = errors;
(0, notifier_util_1.notify)({ subtitle: 'Admin Webpack - Error', message: error.name });
},
clearConsole: false,
compilationSuccessInfo: { messages: [], notes: [] },
});
ShowErrorsPlugin.displaySuccess = () => { };
const adminDefaultWebpack = {
mode: isProduction ? 'production' : 'development',
bail: !isDevelopment,
performance: {
hints: false,
},
devtool: isProduction ? false : 'cheap-module-source-map',
entry: path_util_1.default.admin('index'),
target: 'web',
stats: {
logging: 'error',
all: false,
},
devServer: {
hot: true,
},
output: {
path: path_util_1.default.build('admin'),
publicPath: '/admin/',
filename: isProduction ? '[name].[contenthash:8].js' : '[name].js',
chunkFilename: isProduction
? '[name].[contenthash:8].chunk.js'
: '[name].chunk.js',
},
optimization: {
minimize: isProduction,
minimizer: [
new terser_webpack_plugin_1.default({
terserOptions: {
parse: {
ecma: 2017,
},
compress: {
ecma: 5,
warnings: false,
comparisons: false,
inline: 2,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
ascii_only: true,
},
},
}),
],
runtimeChunk: true,
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
cacheDirectory: true,
cacheCompression: true,
sourceType: 'unambiguous',
presets: [
[
require.resolve('@babel/preset-env'),
{
modules: 'cjs',
},
],
require.resolve('@babel/preset-react'),
require.resolve('@babel/preset-typescript'),
],
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
{
root: ['./src/'],
alias: {
'@admin': './src/admin',
'@drivers': './src/drivers',
'@features': './src/features',
'@interfaces': './src/interfaces',
'@listeners': './src/listeners',
'@models': './src/models',
'@scripts': './src/scripts',
'@server': './src/server',
'@shared': './src/shared',
},
},
],
[
require.resolve('@babel/plugin-transform-runtime'),
{
helpers: true,
regenerator: true,
},
],
],
},
},
],
},
{
test: /\.s?css$/,
exclude: [/\.module.s?[ac]ss$/],
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.module\.s?[ac]ss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
},
},
{
loader: 'sass-loader',
options: {
additionalData: `@import "${path_util_1.default.admin('styles', 'global.scss')}";`,
},
},
],
},
{
test: /\.(svg|eot|otf|ttf|woff|woff2)$/,
use: 'file-loader',
},
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.ico$/],
loader: require.resolve('url-loader'),
options: {
limit: 1000,
},
},
{
test: /\.html$/,
use: require.resolve('html-loader'),
},
{
test: /\.(mp4|webm)$/,
loader: require.resolve('url-loader'),
options: {
limit: 10000,
},
},
],
},
resolve: {
symlinks: false,
extensions: ['.js', '.jsx', '.tsx', '.ts'],
mainFields: ['browser', 'jsnext:main', 'main'],
fallback: {},
},
plugins: [
ShowErrorsPlugin,
new html_webpack_plugin_1.default({
inject: true,
template: path_util_1.default.admin('index.html'),
}),
new mini_css_extract_plugin_1.default({
filename: '[name].[chunkhash].css',
chunkFilename: '[name].[chunkhash].chunkhash.css',
ignoreOrder: true,
}),
process.env.NODE_ENV === 'production' &&
new webpackbar_1.default({ name: 'Admin', color: '#8f47d4' }),
].filter(Boolean),
};
adminDefaultWebpack.plugins.push(new webpack_1.default.DefinePlugin(Object.assign({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), PUBLIC_PATH: webpack_1.default.DefinePlugin.runtimeValue(() => JSON.stringify(adminDefaultWebpack.output.publicPath)), ROUTER_PATH: webpack_1.default.DefinePlugin.runtimeValue(() => JSON.stringify(adminDefaultWebpack.output.publicPath.replace(/\/?$/, ''))), PROJECT_ADMIN_ENTRY: path_util_1.default.exists(path_util_1.default.projectRoot('admin'))
? JSON.stringify(path_util_1.default.projectRoot('admin'))
: null }, (0, env_util_1.definePublicEnv)())));
exports.default = adminDefaultWebpack;