2018-03-21 16:56:30 +01:00
|
|
|
var path = require('path');
|
2018-02-24 23:55:06 +01:00
|
|
|
var webpack = require('webpack');
|
2018-07-11 17:19:36 +02:00
|
|
|
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2018-08-30 16:43:18 +02:00
|
|
|
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
2018-02-24 23:55:06 +01:00
|
|
|
|
2018-09-16 04:20:55 +02:00
|
|
|
module.exports = (env, argv) => {
|
|
|
|
const isDevServer = (env || {}).devServer === true;
|
|
|
|
const isDevelopment = argv.mode === 'development';
|
|
|
|
const outputDirectory = isDevServer ? "dist-dev" : "dist";
|
|
|
|
const entries = {};
|
2019-03-14 05:56:48 +01:00
|
|
|
entries[`${outputDirectory}/engine`] = "./src/engine.jsx";
|
2019-05-10 04:36:04 +02:00
|
|
|
entries[`${outputDirectory}/engineStyle`] = "./src/engineStyle.js";
|
2019-05-07 03:01:06 +02:00
|
|
|
|
|
|
|
const statsConfig = {
|
|
|
|
builtAt: true,
|
|
|
|
children: false,
|
|
|
|
chunks: false,
|
|
|
|
chunkGroups: false,
|
|
|
|
chunkModules: false,
|
|
|
|
chunkOrigins: false,
|
|
|
|
colors: true,
|
|
|
|
entrypoints: true,
|
2018-09-16 04:20:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
2021-04-30 05:52:56 +02:00
|
|
|
'process.env.NODE_ENV': isDevelopment ? "\"development\"" : "\"production\"",
|
2018-09-16 04:20:55 +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",
|
2021-04-30 05:52:56 +02:00
|
|
|
$: "jquery",
|
2018-09-16 04:20:55 +02:00
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
title: "Bitburner" + (isDevelopment ? ' - development' : ""),
|
|
|
|
template: "src/index.html",
|
|
|
|
favicon: "favicon.ico",
|
|
|
|
googleAnalytics: {
|
2021-04-30 05:52:56 +02:00
|
|
|
trackingId: 'UA-100157497-1',
|
2018-09-16 04:20:55 +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,
|
2021-04-30 05:52:56 +02:00
|
|
|
useShortDoctype: false,
|
2018-09-16 04:20:55 +02:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
new MiniCssExtractPlugin({
|
2021-04-30 05:52:56 +02:00
|
|
|
filename: "[name].css",
|
|
|
|
}),
|
2018-09-16 04:20:55 +02:00
|
|
|
],
|
|
|
|
target: "web",
|
|
|
|
entry: entries,
|
|
|
|
devtool: "source-map",
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, "./"),
|
2021-04-30 05:52:56 +02:00
|
|
|
filename: "[name].bundle.js",
|
2018-09-16 04:20:55 +02:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
loader: 'ts-loader',
|
2021-04-30 05:52:56 +02:00
|
|
|
exclude: /node_modules/,
|
2018-09-16 04:20:55 +02:00
|
|
|
},
|
2019-03-13 23:17:30 +01:00
|
|
|
{
|
|
|
|
test: /\.(jsx)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
2021-04-30 05:52:56 +02:00
|
|
|
loader: "babel-loader",
|
|
|
|
},
|
2019-03-13 23:17:30 +01:00
|
|
|
},
|
2018-09-16 04:20:55 +02:00
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
"css-loader",
|
2021-04-30 05:52:56 +02:00
|
|
|
"sass-loader",
|
|
|
|
],
|
2018-09-16 04:20:55 +02:00
|
|
|
},
|
2021-04-30 05:52:56 +02:00
|
|
|
],
|
2018-09-16 04:20:55 +02:00
|
|
|
},
|
|
|
|
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`,
|
2021-04-30 05:52:56 +02:00
|
|
|
chunks: 'all',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-09-16 04:20:55 +02:00
|
|
|
},
|
|
|
|
devServer: {
|
2019-04-10 08:07:12 +02:00
|
|
|
port: 8000,
|
2018-09-16 04:20:55 +02:00
|
|
|
publicPath: `/`,
|
2019-05-07 03:01:06 +02:00
|
|
|
stats: statsConfig,
|
2018-09-16 04:20:55 +02:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: [
|
|
|
|
".tsx",
|
|
|
|
".ts",
|
2019-03-13 23:17:30 +01:00
|
|
|
".js",
|
|
|
|
".jsx",
|
2021-04-30 05:52:56 +02:00
|
|
|
],
|
2019-05-07 03:01:06 +02:00
|
|
|
},
|
|
|
|
stats: statsConfig,
|
2018-09-16 04:20:55 +02:00
|
|
|
};
|
|
|
|
};
|