Skip to content

Instantly share code, notes, and snippets.

@509dave16
Created June 24, 2018 02:05
Show Gist options
  • Save 509dave16/307c1686b5fd49a9177e501d5da049cb to your computer and use it in GitHub Desktop.
Save 509dave16/307c1686b5fd49a9177e501d5da049cb to your computer and use it in GitHub Desktop.
Sample preact.config.js with wepback modifications
/**
* Function that mutates original webpack config.
* Supports asynchronous changes when promise is returned.
*
* @param {object} config - original webpack config.
* @param {object} env - options passed to CLI.
* @param {WebpackConfigHelpers} helpers - object with useful helpers when working with config.
**/
import AggressiveMergingPlugin from "./node_modules/webpack/lib/optimize/AggressiveMergingPlugin";
import CompressionPlugin from "compression-webpack-plugin";
export default function (config, env, helpers) {
// config.resolve.alias['framework7$'] = 'framework7/dist/framework7.esm.bundle';
/** you can change config here **/
if (env.isProd) {
const uglifyDesc = helpers.getPluginsByName(config, 'UglifyJsPlugin').pop();
config.plugins.splice(uglifyDesc.index + 1, 0, new AggressiveMergingPlugin());
config.plugins.splice(uglifyDesc.index + 2, 0, new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
}));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment