@expo/webpack-config
Version:
The default Webpack configuration used to build Expo apps targeting the web.
80 lines • 3.8 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("@expo/config");
const paths_1 = require("@expo/config/paths");
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
const pnp_webpack_plugin_1 = __importDefault(require("pnp-webpack-plugin"));
const env_1 = require("../env");
/**
* Enable or disable TypeScript in the Webpack config that's provided.
* - Disabling will filter out any TypeScript extensions.
* - Enabling will add fork TS checker to the plugins.
*
* @param webpackConfig input Webpack config to modify and return.
* @param env Environment used to configure the input config.
* @category addons
*/
function withTypeScriptAsync(webpackConfig, env = {}) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const isDev = webpackConfig.mode !== 'production';
env.projectRoot = env.projectRoot || paths_1.getPossibleProjectRoot();
// @ts-ignore
env.config = env.config || env_1.getConfig(env);
let typeScriptPath = null;
try {
typeScriptPath = config_1.resolveModule('typescript', env.projectRoot, env.config);
}
catch (_) { }
const tsConfigPath = env_1.getAbsolute(env.projectRoot, 'tsconfig.json');
const isTypeScriptEnabled = Boolean(typeScriptPath && (yield config_1.fileExistsAsync(tsConfigPath)));
if (!isTypeScriptEnabled && ((_a = webpackConfig.resolve) === null || _a === void 0 ? void 0 : _a.extensions)) {
webpackConfig.resolve.extensions = webpackConfig.resolve.extensions.filter(extension => {
// filter out ts and tsx extensions, including .web.ts
return !extension.endsWith('.ts') && !extension.endsWith('.tsx');
});
}
if (!isTypeScriptEnabled) {
return webpackConfig;
}
if (!webpackConfig.plugins)
webpackConfig.plugins = [];
webpackConfig.plugins.push(new fork_ts_checker_webpack_plugin_1.default(pnp_webpack_plugin_1.default.forkTsCheckerOptions({
async: isDev,
typescript: typeScriptPath,
useTypescriptIncrementalApi: true,
checkSyntacticErrors: true,
tsconfig: tsConfigPath,
reportFiles: [
'**',
'!**/__tests__/**',
'!**/?(*.)(spec|test).*',
// Add support for CRA projects
'!**/src/setupProxy.*',
'!**/src/setupTests.*',
],
compilerOptions: {
isolatedModules: true,
noEmit: true,
},
// Disable the formatter in production like CRA
formatter: isDev ? 'codeframe' : undefined,
silent: true,
})));
return webpackConfig;
});
}
exports.default = withTypeScriptAsync;
//# sourceMappingURL=withTypeScriptAsync.js.map