@expo/webpack-config
Version:
The default Webpack configuration used to build Expo apps targeting the web.
56 lines • 2.35 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const paths_1 = require("@expo/config/paths");
const compression_webpack_plugin_1 = __importDefault(require("compression-webpack-plugin"));
const env_1 = require("../env");
const utils_1 = require("../utils");
/**
* @internal
*/
exports.DEFAULT_GZIP_OPTIONS = {
test: /static\/.*\.(js|css)$/,
filename: '[path].gz[query]',
algorithm: 'gzip',
threshold: 1024,
minRatio: 0.8,
};
/**
* Add production compression options to the provided Webpack config.
*
* @param webpackConfig Existing Webpack config to modify.
* @param env Environment used for getting the Expo project config.
* @category addons
*/
function withCompression(webpackConfig, env) {
if (webpackConfig.mode !== 'production') {
return webpackConfig;
}
env.projectRoot = env.projectRoot || paths_1.getPossibleProjectRoot();
const config = env_1.getConfig(env);
return addCompressionPlugins(webpackConfig, config);
}
exports.default = withCompression;
/**
* Add Gzip compression to the provided Webpack config.
*
* @param webpackConfig Existing Webpack config to modify.
* @param expoConfig Expo config with compression options.
* @internal
*/
function addCompressionPlugins(webpackConfig, expoConfig) {
var _a, _b, _c, _d;
const gzipConfig = utils_1.overrideWithPropertyOrConfig((_b = (_a = expoConfig.web) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.gzip, exports.DEFAULT_GZIP_OPTIONS, true);
if (typeof ((_d = (_c = expoConfig.web) === null || _c === void 0 ? void 0 : _c.build) === null || _d === void 0 ? void 0 : _d.brotli) !== 'undefined') {
console.warn('The app.json value `expo.web.build.brotli` has been deprecated. You can add Brotli support manually by customizing the Webpack config with `expo customize:web`.');
}
if (!Array.isArray(webpackConfig.plugins))
webpackConfig.plugins = [];
if (gzipConfig)
webpackConfig.plugins.push(new compression_webpack_plugin_1.default(gzipConfig));
return webpackConfig;
}
exports.addCompressionPlugins = addCompressionPlugins;
//# sourceMappingURL=withCompression.js.map