Files
Bubberstation/tgui/webpack.config.js
Jeremiah 4165d8a3ba tgui: adds tgui npm library (#83789)
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request
As a side project I've been building an npm library for tgui components.
~~I'd like to see if it works~~. It functions as a straight one-line
replacement for interfaces and, if fully implemented, allows you to
totally delete your tgui/components and tgui/styles/components folders

This is a test of 10 mostly random UIs

>[!NOTE]
>Link to the repo:
>https://github.com/tgstation/tgui-core
>
>Link to the npm package
>https://www.npmjs.com/package/tgui-core

<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

## Why It's Good For The Game
This is nice because it allows us to easily distribute the gospel of TG
to downstreams without them having to sift through our PRs and code (as
much as I want to make them) just to assess parity. With tgui-core
you're getting the most up-to-date TGUI components without having to
fiddle with integrating them or copy pasting.

It also allows me and other TGUI(tm) contributors (all 2 other people
maybe) to collectively work across borders on improving and maintaining
tgui without causing significant deviations and requiring
upstream/downstream ports to fix them.

EDIT: Someone asked how would this allow them to make their own custom
versions. You still can, and you can even use both interoperably, by
simply changing where you're importing the component from. It's opt in
to use tgui-core components.
<!-- Argue for the merits of your changes and how they benefit the game,
especially if they are controversial and/or far reaching. If you can't
actually explain WHY what you are doing will improve the game, then it
probably isn't good for the game in the first place. -->

## Changelog

n/a these are identical tgui components
2024-06-26 17:14:13 -07:00

161 lines
3.7 KiB
JavaScript

/**
* @file
* @copyright 2020 Aleksej Komarov
* @license MIT
*/
const webpack = require('webpack');
const path = require('path');
const ExtractCssPlugin = require('mini-css-extract-plugin');
const createStats = (verbose) => ({
assets: verbose,
builtAt: verbose,
cached: false,
children: false,
chunks: false,
colors: true,
entrypoints: true,
hash: false,
modules: false,
performance: false,
timings: verbose,
version: verbose,
});
module.exports = (env = {}, argv) => {
const mode = argv.mode || 'production';
const bench = env.TGUI_BENCH;
const config = {
mode: mode === 'production' ? 'production' : 'development',
context: path.resolve(__dirname),
target: ['web', 'es5', 'browserslist:ie 11'],
entry: {
tgui: ['./packages/tgui-polyfill', './packages/tgui'],
'tgui-panel': ['./packages/tgui-polyfill', './packages/tgui-panel'],
'tgui-say': ['./packages/tgui-polyfill', './packages/tgui-say'],
},
output: {
path: argv.useTmpFolder
? path.resolve(__dirname, './public/.tmp')
: path.resolve(__dirname, './public'),
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
chunkLoadTimeout: 15000,
publicPath: '/',
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx'],
alias: {},
},
module: {
rules: [
{
test: /\.([tj]s(x)?|cjs)$/,
exclude: /node_modules[\\/]core-js/,
use: [
{
loader: require.resolve('swc-loader'),
},
],
},
{
test: /\.(s)?css$/,
use: [
{
loader: ExtractCssPlugin.loader,
options: {
esModule: false,
},
},
{
loader: require.resolve('css-loader'),
options: {
esModule: false,
},
},
{
loader: require.resolve('sass-loader'),
},
],
},
{
test: /\.(png|jpg|svg)$/,
use: [
{
loader: require.resolve('url-loader'),
options: {
esModule: false,
},
},
],
},
],
},
optimization: {
emitOnErrors: false,
},
performance: {
hints: false,
},
devtool: false,
cache: {
type: 'filesystem',
cacheLocation: path.resolve(__dirname, `.yarn/webpack/${mode}`),
buildDependencies: {
config: [__filename],
},
},
stats: createStats(true),
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: env.NODE_ENV || mode,
WEBPACK_HMR_ENABLED: env.WEBPACK_HMR_ENABLED || argv.hot || false,
DEV_SERVER_IP: env.DEV_SERVER_IP || null,
}),
new ExtractCssPlugin({
filename: '[name].bundle.css',
chunkFilename: '[name].bundle.css',
}),
],
};
if (bench) {
config.entry = {
'tgui-bench': [
'./packages/tgui-polyfill',
'./packages/tgui-bench/entrypoint',
],
};
}
// Production build specific options
if (mode === 'production') {
const { EsbuildPlugin } = require('esbuild-loader');
config.optimization.minimizer = [
new EsbuildPlugin({
target: 'ie11',
css: true,
}),
];
}
// Development build specific options
if (mode !== 'production') {
config.devtool = 'cheap-module-source-map';
}
// Development server specific options
if (argv.devServer) {
config.devServer = {
progress: false,
quiet: false,
noInfo: false,
clientLogLevel: 'silent',
stats: createStats(false),
};
}
return config;
};