[chore] fixing the ability to run dev-server

This commit is contained in:
Steven Evans 2018-09-15 22:20:55 -04:00 committed by danielyxie
parent a98dd66e45
commit c87621edd9
2 changed files with 125 additions and 117 deletions

@ -93,7 +93,7 @@
"url": "git+https://github.com/danielyxie/bitburner.git" "url": "git+https://github.com/danielyxie/bitburner.git"
}, },
"scripts": { "scripts": {
"start:dev": "webpack-dev-server", "start:dev": "webpack-dev-server --progress --env.devServer --mode development",
"build": "webpack --mode production", "build": "webpack --mode production",
"build:dev": "webpack --mode development", "build:dev": "webpack --mode development",
"lint": "npm run lint:typescript & npm run lint:javascript & npm run lint:style", "lint": "npm run lint:typescript & npm run lint:javascript & npm run lint:style",

@ -3,123 +3,131 @@ var webpack = require('webpack');
var MiniCssExtractPlugin = require('mini-css-extract-plugin'); var MiniCssExtractPlugin = require('mini-css-extract-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin'); var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = (env, argv) => ({ module.exports = (env, argv) => {
plugins: [ const isDevServer = (env || {}).devServer === true;
new webpack.DefinePlugin({ const isDevelopment = argv.mode === 'development';
'process.env.NODE_ENV': argv.mode === 'development' ? "\"development\"" : "\"production\"" const outputDirectory = isDevServer ? "dist-dev" : "dist";
}), const entries = {};
// http://stackoverflow.com/questions/29080148/expose-jquery-to-real-window-object-with-webpack entries[`${outputDirectory}/engine`] = "./src/engine.js";
new webpack.ProvidePlugin({ if (!isDevServer) {
// Automtically detect jQuery and $ as free var in modules entries["tests/tests"] = "./tests/index.js";
// and inject the jquery library }
// This is required by many jquery plugins
jquery: "jquery", return {
jQuery: "jquery", plugins: [
$: "jquery" new webpack.DefinePlugin({
}), 'process.env.NODE_ENV': isDevelopment ? "\"development\"" : "\"production\""
new HtmlWebpackPlugin({ }),
title: "Bitburner" + (argv.mode === 'development' ? ' - development' : ""), // http://stackoverflow.com/questions/29080148/expose-jquery-to-real-window-object-with-webpack
template: "src/index.html", new webpack.ProvidePlugin({
favicon: "favicon.ico", // Automtically detect jQuery and $ as free var in modules
googleAnalytics: { // and inject the jquery library
trackingId: 'UA-100157497-1' // This is required by many jquery plugins
}, jquery: "jquery",
meta: {}, jQuery: "jquery",
minify: argv.mode === 'development' ? false : { $: "jquery"
collapseBooleanAttributes: true, }),
collapseInlineTagWhitespace: false, new HtmlWebpackPlugin({
collapseWhitespace: false, title: "Bitburner" + (isDevelopment ? ' - development' : ""),
conservativeCollapse: false, template: "src/index.html",
html5: true, favicon: "favicon.ico",
includeAutoGeneratedTags: false, googleAnalytics: {
keepClosingSlash: true, trackingId: 'UA-100157497-1'
minifyCSS: false, },
minifyJS: false, meta: {},
minifyURLs: false, minify: isDevelopment ? false : {
preserveLineBreaks: false, collapseBooleanAttributes: true,
preventAttributesEscaping: false, collapseInlineTagWhitespace: false,
processConditionalComments: false, collapseWhitespace: false,
quoteCharacter: "\"", conservativeCollapse: false,
removeAttributeQuotes: false, html5: true,
removeComments: false, includeAutoGeneratedTags: false,
removeEmptyAttributes: false, keepClosingSlash: true,
removeEmptyElements: false, minifyCSS: false,
removeOptionalTags: false, minifyJS: false,
removeScriptTypeAttributes: false, minifyURLs: false,
removeStyleLinkTypeAttributes: false, preserveLineBreaks: false,
removeTagWhitespace: false, preventAttributesEscaping: false,
sortAttributes: false, processConditionalComments: false,
sortClassName: false, quoteCharacter: "\"",
useShortDoctype: false removeAttributeQuotes: false,
}, removeComments: false,
excludeChunks: [ removeEmptyAttributes: false,
"tests/tests" removeEmptyElements: false,
] removeOptionalTags: false,
}), removeScriptTypeAttributes: false,
new MiniCssExtractPlugin({ removeStyleLinkTypeAttributes: false,
filename: "[name].css", removeTagWhitespace: false,
chunkFilename: "[id].css" sortAttributes: false,
}) sortClassName: false,
], useShortDoctype: false
target: "web", },
entry: { excludeChunks: [
"dist/engine": "./src/engine.js", "tests/tests"
"tests/tests": "./tests/index.js",
},
devtool: "source-map",
output: {
path: path.resolve(__dirname, "./"),
filename: "[name].bundle.js"
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader"
] ]
}, }),
] new MiniCssExtractPlugin({
}, filename: "[name].css",
optimization: { chunkFilename: "[id].css"
removeAvailableModules: true, })
removeEmptyChunks: true, ],
mergeDuplicateChunks: true, target: "web",
flagIncludedChunks: true, entry: entries,
occurrenceOrder: true, devtool: "source-map",
sideEffects: true, output: {
providedExports: true, path: path.resolve(__dirname, "./"),
usedExports: true, filename: "[name].bundle.js"
concatenateModules: false, },
namedModules: false, module: {
namedChunks: false, rules: [
minimize: argv.mode !== 'development', {
portableRecords: true, test: /\.tsx?$/,
splitChunks: { loader: 'ts-loader',
cacheGroups: { exclude: /node_modules/
vendor: { },
test: /[\\/]node_modules[\\/]/, {
name: 'dist/vendor', test: /\.s?css$/,
chunks: 'all' 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: {
publicPath: `/`,
},
resolve: {
extensions: [
".tsx",
".ts",
".js"
]
} }
}, };
devServer: { };
publicPath: "/dist",
},
resolve: {
extensions: [
".tsx",
".ts",
".js"
]
}
});