2021-05-29 20:48:56 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2021-09-05 20:10:23 +02:00
|
|
|
const path = require("path");
|
|
|
|
const webpack = require("webpack");
|
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
|
|
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
2021-09-13 05:23:09 +02:00
|
|
|
const UnusedWebpackPlugin = require("unused-webpack-plugin");
|
2018-02-24 23:55:06 +01:00
|
|
|
|
2018-09-16 04:20:55 +02:00
|
|
|
module.exports = (env, argv) => {
|
2021-09-05 01:09:30 +02:00
|
|
|
const isDevServer = (env || {}).devServer === true;
|
|
|
|
const runInContainer = (env || {}).runInContainer === true;
|
|
|
|
const isDevelopment = argv.mode === "development";
|
|
|
|
const outputDirectory = isDevServer ? "dist-dev" : "dist";
|
|
|
|
const entries = {};
|
|
|
|
entries[`${outputDirectory}/engine`] = "./src/engine.jsx";
|
|
|
|
entries[`${outputDirectory}/engineStyle`] = "./src/engineStyle.js";
|
2019-05-07 03:01:06 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
const statsConfig = {
|
|
|
|
builtAt: true,
|
|
|
|
children: false,
|
|
|
|
chunks: false,
|
|
|
|
chunkGroups: false,
|
|
|
|
chunkModules: false,
|
|
|
|
chunkOrigins: false,
|
|
|
|
colors: true,
|
2021-09-05 20:31:40 +02:00
|
|
|
entrypoints: false,
|
2021-09-05 01:09:30 +02:00
|
|
|
};
|
2018-09-16 04:20:55 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
const devServerSettings = {
|
|
|
|
port: 8000,
|
|
|
|
publicPath: `/`,
|
|
|
|
stats: statsConfig,
|
|
|
|
};
|
2021-05-08 21:02:26 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// By default, the webpack-dev-server is not exposed outside of localhost.
|
|
|
|
// When running in a container we need it accessible externally.
|
|
|
|
if (runInContainer) {
|
|
|
|
devServerSettings.disableHostCheck = true;
|
|
|
|
devServerSettings.host = "0.0.0.0";
|
|
|
|
devServerSettings.watchOptions = {
|
|
|
|
poll: true,
|
|
|
|
};
|
|
|
|
}
|
2021-05-08 21:02:26 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return {
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
2021-09-09 05:47:34 +02:00
|
|
|
"process.env.NODE_ENV": isDevelopment ? '"development"' : '"production"',
|
2021-09-05 01:09:30 +02:00
|
|
|
}),
|
|
|
|
// http://stackoverflow.com/questions/29080148/expose-jquery-to-real-window-object-with-webpack
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
// Automtically detect jQuery and $ as free var in modules
|
|
|
|
// and inject the jquery library
|
|
|
|
// This is required by many jquery plugins
|
|
|
|
jquery: "jquery",
|
|
|
|
jQuery: "jquery",
|
|
|
|
$: "jquery",
|
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
title: "Bitburner" + (isDevelopment ? " - development" : ""),
|
|
|
|
template: "src/index.html",
|
|
|
|
favicon: "favicon.ico",
|
|
|
|
googleAnalytics: {
|
|
|
|
trackingId: "UA-100157497-1",
|
2018-09-16 04:20:55 +02:00
|
|
|
},
|
2021-09-05 01:09:30 +02:00
|
|
|
meta: {},
|
|
|
|
minify: isDevelopment
|
|
|
|
? false
|
|
|
|
: {
|
|
|
|
collapseBooleanAttributes: true,
|
|
|
|
collapseInlineTagWhitespace: false,
|
|
|
|
collapseWhitespace: false,
|
|
|
|
conservativeCollapse: false,
|
|
|
|
html5: true,
|
|
|
|
includeAutoGeneratedTags: false,
|
|
|
|
keepClosingSlash: true,
|
|
|
|
minifyCSS: false,
|
|
|
|
minifyJS: false,
|
|
|
|
minifyURLs: false,
|
|
|
|
preserveLineBreaks: false,
|
|
|
|
preventAttributesEscaping: false,
|
|
|
|
processConditionalComments: false,
|
|
|
|
quoteCharacter: '"',
|
|
|
|
removeAttributeQuotes: false,
|
|
|
|
removeComments: false,
|
|
|
|
removeEmptyAttributes: false,
|
|
|
|
removeEmptyElements: false,
|
|
|
|
removeOptionalTags: false,
|
|
|
|
removeScriptTypeAttributes: false,
|
|
|
|
removeStyleLinkTypeAttributes: false,
|
|
|
|
removeTagWhitespace: false,
|
|
|
|
sortAttributes: false,
|
|
|
|
sortClassName: false,
|
|
|
|
useShortDoctype: false,
|
2021-04-30 05:52:56 +02:00
|
|
|
},
|
2021-09-05 01:09:30 +02:00
|
|
|
}),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: "[name].css",
|
|
|
|
}),
|
2021-09-05 20:10:23 +02:00
|
|
|
new ForkTsCheckerWebpackPlugin({
|
|
|
|
typescript: {
|
|
|
|
diagnosticOptions: {
|
|
|
|
semantic: true,
|
|
|
|
syntactic: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2021-09-13 05:23:09 +02:00
|
|
|
new UnusedWebpackPlugin({
|
|
|
|
// Source directories
|
|
|
|
directories: [path.join(__dirname, "src"), path.join(__dirname, "utils")],
|
|
|
|
// Exclude patterns
|
|
|
|
exclude: ["*.test.js"],
|
|
|
|
// Root directory (optional)
|
|
|
|
root: __dirname,
|
|
|
|
}),
|
2021-09-05 20:31:40 +02:00
|
|
|
// In dev mode, use a faster method of create sourcemaps
|
|
|
|
// while keeping lines/columns accurate
|
|
|
|
isDevServer &&
|
|
|
|
new webpack.EvalSourceMapDevToolPlugin({
|
|
|
|
// Exclude vendor files from sourcemaps
|
|
|
|
// This is a huge speed improvement for not much loss
|
|
|
|
exclude: ["vendor"],
|
|
|
|
columns: true,
|
|
|
|
module: true,
|
|
|
|
}),
|
|
|
|
!isDevServer &&
|
|
|
|
new webpack.SourceMapDevToolPlugin({
|
|
|
|
filename: "[file].map",
|
|
|
|
columns: true,
|
|
|
|
module: true,
|
|
|
|
}),
|
|
|
|
].filter(Boolean),
|
2021-09-05 01:09:30 +02:00
|
|
|
target: "web",
|
|
|
|
entry: entries,
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, "./"),
|
|
|
|
filename: "[name].bundle.js",
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2021-09-05 07:17:30 +02:00
|
|
|
test: /\.(js|jsx|ts|tsx)$/,
|
2021-09-05 01:09:30 +02:00
|
|
|
exclude: /node_modules/,
|
2021-09-05 02:52:23 +02:00
|
|
|
use: {
|
2021-09-05 07:17:30 +02:00
|
|
|
loader: "babel-loader",
|
2021-09-05 02:52:23 +02:00
|
|
|
options: {
|
2021-09-05 07:17:30 +02:00
|
|
|
cacheDirectory: true,
|
2021-09-05 02:52:23 +02:00
|
|
|
},
|
2021-09-05 01:09:30 +02:00
|
|
|
},
|
2019-05-07 03:01:06 +02:00
|
|
|
},
|
2021-09-05 01:09:30 +02:00
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
removeAvailableModules: true,
|
|
|
|
removeEmptyChunks: true,
|
|
|
|
mergeDuplicateChunks: true,
|
|
|
|
flagIncludedChunks: true,
|
|
|
|
occurrenceOrder: true,
|
|
|
|
sideEffects: true,
|
|
|
|
providedExports: true,
|
|
|
|
usedExports: true,
|
|
|
|
concatenateModules: false,
|
|
|
|
namedModules: false,
|
|
|
|
namedChunks: false,
|
|
|
|
minimize: !isDevelopment,
|
|
|
|
portableRecords: true,
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
vendor: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
name: `${outputDirectory}/vendor`,
|
|
|
|
chunks: "all",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
devServer: devServerSettings,
|
|
|
|
resolve: {
|
|
|
|
extensions: [".tsx", ".ts", ".js", ".jsx"],
|
|
|
|
},
|
|
|
|
stats: statsConfig,
|
|
|
|
};
|
2018-09-16 04:20:55 +02:00
|
|
|
};
|