Files
cellxgene/client/configuration/webpack/webpack.config.prod.js
T
Bruce Martin f42f5151a6 Refactor build and CSP headers for Safari compat (#1442)
* add unsafe-inline directive to style-src

* debugging - turn on csp reporting

* revert reporting only csp

* do not inline JS and CSS in build

* enable HTTPs only when in production mode

* remove debug printf

* fix clean target

* revert force_https removal
2020-05-04 12:47:35 -07:00

135 lines
3.5 KiB
JavaScript

// jshint esversion: 6
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackInlineSourcePlugin = require("html-webpack-inline-source-plugin");
const FaviconsWebpackPlugin = require("favicons-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const TerserJSPlugin = require("terser-webpack-plugin");
const CleanCss = require("clean-css");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const CspHashPlugin = require("./cspHashPlugin");
const src = path.resolve("src");
const fonts = path.resolve("src/fonts");
const nodeModules = path.resolve("node_modules");
const babelOptions = require("../babel/babel.prod");
const publicPath = "/";
module.exports = {
mode: "production",
bail: true,
cache: false,
entry: ["./src/index.js"],
output: {
filename: "static/[name]-[contenthash].js",
path: path.resolve("build"),
publicPath,
},
optimization: {
minimize: true,
minimizer: [
new TerserJSPlugin({}),
new OptimizeCSSAssetsPlugin({
cssProcessor: CleanCss,
}),
],
},
module: {
rules: [
{
test: /\.js$/,
include: src,
loader: "babel-loader",
options: babelOptions,
},
{
test: /\.css$/,
include: src,
exclude: [path.resolve(src, "index.css")],
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
modules: {
localIdentName: "[name]__[local]___[hash:base64:5]",
},
importLoaders: 1,
},
},
],
},
{
test: /index\.css$/,
include: [path.resolve(src, "index.css")],
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.json$/,
include: [src, nodeModules],
loader: "json-loader",
exclude: /manifest.json$/,
},
{
test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2|otf)$/i,
loader: "file-loader",
include: [nodeModules, fonts],
query: { name: "static/assets/[name]-[contenthash].[ext]" },
},
],
},
plugins: [
new HtmlWebpackPlugin({
filename: "index.html",
template: path.resolve("index_template.html"),
decodeEntities: false,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
new CleanWebpackPlugin({
verbose: true,
protectWebpackAssets: false,
cleanAfterEveryBuildPatterns: ["main.js", "main.css"],
}),
new FaviconsWebpackPlugin({
logo: "./favicon.png",
prefix: "static/assets/",
favicons: {
icons: {
android: false,
appleIcon: false,
appleStartup: false,
coast: false,
firefox: false,
windows: false,
yandex: false,
},
},
}),
new MiniCssExtractPlugin({
filename: "static/[name]-[contenthash].css",
}),
new CspHashPlugin({
filename: "csp-hashes.json",
}),
],
performance: {
maxEntrypointSize: 2000000,
maxAssetSize: 2000000,
},
};