UNPKG

@expo/webpack-config

Version:

The default Webpack configuration used to build Expo apps targeting the web.

44 lines 1.96 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const compression_webpack_plugin_1 = __importDefault(require("compression-webpack-plugin")); const brotli_webpack_plugin_1 = __importDefault(require("brotli-webpack-plugin")); const utils_1 = require("../utils"); const env_1 = require("../env"); exports.DEFAULT_GZIP_OPTIONS = { test: /\.(js|css)$/, filename: '[path].gz[query]', algorithm: 'gzip', threshold: 1024, minRatio: 0.8, }; exports.DEFAULT_BROTLI_OPTIONS = { asset: '[path].br[query]', test: /\.(js|css)$/, threshold: 1024, minRatio: 0.8, }; function withCompression(webpackConfig, env) { if (webpackConfig.mode !== 'production') { return webpackConfig; } const config = env_1.getConfig(env); return addCompressionPlugins(webpackConfig, config); } exports.default = withCompression; function addCompressionPlugins(webpackConfig, config) { var _a, _b, _c, _d; const gzipConfig = utils_1.overrideWithPropertyOrConfig((_b = (_a = config.web) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.gzip, exports.DEFAULT_GZIP_OPTIONS, true); const brotliConfig = utils_1.enableWithPropertyOrConfig((_d = (_c = config.web) === null || _c === void 0 ? void 0 : _c.build) === null || _d === void 0 ? void 0 : _d.brotli, exports.DEFAULT_BROTLI_OPTIONS, true); if (!Array.isArray(webpackConfig.plugins)) webpackConfig.plugins = []; if (gzipConfig) webpackConfig.plugins.push(new compression_webpack_plugin_1.default(gzipConfig)); if (brotliConfig) webpackConfig.plugins.push(new brotli_webpack_plugin_1.default(brotliConfig)); return webpackConfig; } exports.addCompressionPlugins = addCompressionPlugins; //# sourceMappingURL=withCompression.js.map