2018-02-26 00:11:31 +00:00
|
|
|
const ManifestPlugin = require('webpack-manifest-plugin');
|
2019-04-14 16:03:28 +00:00
|
|
|
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2019-12-29 17:54:12 +00:00
|
|
|
const CompressionPlugin = require('compression-webpack-plugin');
|
|
|
|
const ProgmemGenerator = require('./progmem-generator.js');
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
module.exports = function override(config, env) {
|
|
|
|
if (env === "production") {
|
|
|
|
// rename the ouput file, we need it's path to be short, for SPIFFS
|
2019-04-14 16:03:28 +00:00
|
|
|
config.output.filename = 'js/[id].[chunkhash:4].js';
|
|
|
|
config.output.chunkFilename = 'js/[id].[chunkhash:4].js';
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-04-14 16:03:28 +00:00
|
|
|
// take out the manifest and service worker plugins
|
2018-02-26 00:11:31 +00:00
|
|
|
config.plugins = config.plugins.filter(plugin => !(plugin instanceof ManifestPlugin));
|
2019-04-14 16:03:28 +00:00
|
|
|
config.plugins = config.plugins.filter(plugin => !(plugin instanceof WorkboxWebpackPlugin.GenerateSW));
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-04-14 16:03:28 +00:00
|
|
|
// shorten css filenames
|
|
|
|
const miniCssExtractPlugin = config.plugins.find((plugin) => plugin instanceof MiniCssExtractPlugin);
|
|
|
|
miniCssExtractPlugin.options.filename = "css/[id].[contenthash:4].css";
|
|
|
|
miniCssExtractPlugin.options.chunkFilename = "css/[id].[contenthash:4].c.css";
|
2018-03-29 08:57:52 +00:00
|
|
|
|
2019-12-29 17:54:12 +00:00
|
|
|
// build progmem data files
|
|
|
|
config.plugins.push(new ProgmemGenerator({ outputPath: "../lib/framework/WWWData.h", bytesPerLine: 20 }));
|
|
|
|
|
2018-11-11 17:53:58 +00:00
|
|
|
// add compression plugin, compress javascript
|
2018-02-26 00:11:31 +00:00
|
|
|
config.plugins.push(new CompressionPlugin({
|
2019-04-14 16:03:28 +00:00
|
|
|
filename: "[path].gz[query]",
|
2018-02-26 00:11:31 +00:00
|
|
|
algorithm: "gzip",
|
2018-11-11 17:53:58 +00:00
|
|
|
test: /\.(js)$/,
|
2018-02-26 00:11:31 +00:00
|
|
|
deleteOriginalAssets: true
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
return config;
|
|
|
|
}
|