1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 21:20:24 +02:00

Move Typescript configuration to webpack config from core (#11)

This commit is contained in:
David Wheatley
2021-05-12 01:28:31 +01:00
committed by GitHub
parent 3610f08d6b
commit 4bdb02a878
5 changed files with 1588 additions and 10961 deletions

View File

@@ -1,52 +1,72 @@
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const entryPointNames = ['forum', 'admin'];
const entryPointExts = ['js', 'ts'];
function getEntryPoints() {
const entries = {};
appLoop: for (const app of entryPointNames) {
for (const ext of entryPointExts) {
const file = path.resolve(process.cwd(), `${app}.${ext}`);
if (fs.existsSync(file)) {
entries[app] = file;
continue appLoop;
}
}
}
if (Object.keys(entries).length === 0) {
console.error('ERROR: No JS entrypoints could be found.');
}
return entries;
}
module.exports = function (options = {}) {
return {
// Set up entry points for each of the forum + admin apps, but only
// if they exist.
entry: (function () {
const entries = {};
entry: getEntryPoints(),
for (const app of ['forum', 'admin']) {
const file = path.resolve(process.cwd(), app + '.js');
if (fs.existsSync(file)) {
entries[app] = file;
}
}
return entries;
})(),
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
modules: false,
loose: true,
},
],
['@babel/preset-react'],
// Matches .js, .jsx, .ts, .tsx
// See: https://regexr.com/5snjd
test: /\.(j|t)sx?$/,
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-react',
'@babel/preset-typescript',
[
'@babel/preset-env',
{
modules: false,
loose: true,
},
],
plugins: [
['@babel/plugin-transform-runtime', { useESModules: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
['@babel/plugin-transform-react-jsx', {
],
plugins: [
['@babel/plugin-transform-runtime', { useESModules: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
[
'@babel/plugin-transform-react-jsx',
{
pragma: 'm',
pragmaFrag: "'['",
useBuiltIns: true,
}],
},
],
},
],
},
},
],