fleet/webpack.config.js

146 lines
3.8 KiB
JavaScript
Raw Normal View History

require("es6-promise").polyfill();
const path = require("path");
const webpack = require("webpack");
const bourbon = require("node-bourbon").includePaths;
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const WebpackNotifierPlugin = require("webpack-notifier");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const DEV_SOURCE_MAPS = "eval-source-map";
let plugins = [
new ForkTsCheckerWebpackPlugin(),
2017-01-19 15:24:10 +00:00
new HtmlWebpackPlugin({
filename: "../frontend/templates/react.tmpl",
inject: false,
templateParameters: {
isProduction: process.env.NODE_ENV === "production",
},
template: "frontend/templates/react.ejs",
2017-03-13 19:13:33 +00:00
}),
new WebpackNotifierPlugin({
excludeWarnings: true,
}),
];
if (process.env.NODE_ENV === "production") {
2017-01-19 15:24:10 +00:00
plugins = plugins.concat([
new webpack.DefinePlugin({
"process.env": { NODE_ENV: JSON.stringify("production") },
}),
new MiniCssExtractPlugin({
filename: "bundle-[contenthash].css",
allChunks: false,
2017-01-19 15:24:10 +00:00
}),
]);
} else {
// development
2017-01-19 15:24:10 +00:00
plugins = plugins.concat([
new MiniCssExtractPlugin({ filename: "bundle.css", allChunks: false }),
2017-01-19 15:24:10 +00:00
]);
}
const repo = __dirname;
2016-08-10 15:31:27 +00:00
const config = {
2019-07-29 16:40:16 +00:00
mode: process.env.NODE_ENV,
entry: {
bundle: path.join(repo, "frontend/index.jsx"),
},
output: {
path: path.join(repo, "assets/"),
publicPath: "/assets/",
filename: "[name].js",
},
devtool: process.env.NODE_ENV === "development" ? DEV_SOURCE_MAPS : false,
plugins,
2019-07-29 16:40:16 +00:00
optimization: {
minimize: process.env.NODE_ENV === "production",
2019-07-29 16:40:16 +00:00
},
module: {
// The following noParse suppresses the warning about sqlite-parser being a
// pre-compiled JS file. See https://goo.gl/N4s6bB.
noParse: /node_modules\/sqlite-parser\/dist\/sqlite-parser-min.js/,
2017-03-13 19:13:33 +00:00
rules: [
{
test: /\.(png|gif)$/,
use: { loader: "url-loader?name=[name]@[hash].[ext]&limit=6000" },
},
{
test: /\.(pdf|ico|jpg|svg|eot|otf|woff|woff2|ttf|mp4|webm)$/,
use: {
loader: "file-loader",
options: {
name: "[name]@[hash].[ext]",
useRelativePath: true,
},
},
},
{
test: /(\.tsx?|\.jsx?)$/,
exclude: /node_modules/,
use: {
loader: "esbuild-loader",
options: {
loader: "tsx", // Or 'ts' if you don't need tsx
target: "es2016",
},
},
},
{
test: /\.scss$/,
exclude: /node_modules/,
2019-07-29 16:40:16 +00:00
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: "./",
hmr: process.env.NODE_ENV === "development",
2019-07-29 16:40:16 +00:00
},
},
{ loader: "css-loader" },
{ loader: "postcss-loader" },
2017-03-13 19:13:33 +00:00
{
loader: "sass-loader",
2017-03-13 19:13:33 +00:00
options: {
sourceMap: true,
includePaths: [bourbon],
},
2017-03-13 19:13:33 +00:00
},
{ loader: "import-glob-loader" },
2019-07-29 16:40:16 +00:00
],
},
{
2016-10-21 15:57:33 +00:00
test: /\.css$/,
2019-07-29 16:40:16 +00:00
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV === "development",
2019-07-29 16:40:16 +00:00
},
},
"css-loader",
"postcss-loader",
2019-07-29 16:40:16 +00:00
],
},
{
test: /\.jsx?$/,
include: path.join(repo, "frontend"),
use: { loader: "babel-loader", options: { cacheDirectory: true } },
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".jsx", ".json"],
modules: [path.resolve(path.join(repo, "./frontend")), "node_modules"],
},
};
if (process.env.NODE_ENV === "production") {
config.output.filename = "[name]-[hash].js";
2017-01-19 15:24:10 +00:00
}
module.exports = config;