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

@ -14,6 +14,12 @@ module.exports = config(options);
To merge in custom Webpack config options, use [webpack-merge](https://www.npmjs.com/package/webpack-merge). To merge in custom Webpack config options, use [webpack-merge](https://www.npmjs.com/package/webpack-merge).
## Typescript
You'll need to configure a `tsconfig.json` file to ensure your IDE sets up Typescript support correctly.
For details about this, see the [`flarum/flarum-tsconfig` repository](https://github.com/flarum/flarum-tsconfig)
## Options ## Options
### `useExtensions` ### `useExtensions`
@ -34,6 +40,6 @@ import { Tag } from '@flarum/tags/forum';
```js ```js
module.exports = config({ module.exports = config({
useExtensions: ['flarum/tags'] useExtensions: ['flarum/tags'],
}); });
``` ```

View File

@ -1,52 +1,72 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); 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 = {}) { module.exports = function (options = {}) {
return { return {
// Set up entry points for each of the forum + admin apps, but only // Set up entry points for each of the forum + admin apps, but only
// if they exist. // if they exist.
entry: (function () { entry: getEntryPoints(),
const entries = {};
for (const app of ['forum', 'admin']) { resolve: {
const file = path.resolve(process.cwd(), app + '.js'); extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
if (fs.existsSync(file)) { },
entries[app] = file;
}
}
return entries;
})(),
module: { module: {
rules: [ rules: [
{ {
test: /\.js$/, // Matches .js, .jsx, .ts, .tsx
use: { // See: https://regexr.com/5snjd
loader: 'babel-loader', test: /\.(j|t)sx?$/,
options: { loader: 'babel-loader',
presets: [ options: {
[ presets: [
'@babel/preset-env', '@babel/preset-react',
{ '@babel/preset-typescript',
modules: false, [
loose: true, '@babel/preset-env',
}, {
], modules: false,
['@babel/preset-react'], loose: true,
},
], ],
plugins: [ ],
['@babel/plugin-transform-runtime', { useESModules: true }], plugins: [
['@babel/plugin-proposal-class-properties', { loose: true }], ['@babel/plugin-transform-runtime', { useESModules: true }],
['@babel/plugin-proposal-private-methods', { loose: true }], ['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-transform-react-jsx', { ['@babel/plugin-proposal-private-methods', { loose: true }],
[
'@babel/plugin-transform-react-jsx',
{
pragma: 'm', pragma: 'm',
pragmaFrag: "'['", pragmaFrag: "'['",
useBuiltIns: true, useBuiltIns: true,
}], },
], ],
}, ],
}, },
}, },
], ],

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
"author": "Flarum Team", "author": "Flarum Team",
"license": "MIT", "license": "MIT",
"peerDependencies": { "peerDependencies": {
"webpack": "^4.0.0" "webpack": "^4.46.0"
}, },
"dependencies": { "dependencies": {
"@babel/core": "^7.14.0", "@babel/core": "^7.14.0",
@ -15,12 +15,15 @@
"@babel/plugin-transform-object-assign": "^7.12.13", "@babel/plugin-transform-object-assign": "^7.12.13",
"@babel/plugin-transform-react-jsx": "^7.13.12", "@babel/plugin-transform-react-jsx": "^7.13.12",
"@babel/plugin-transform-runtime": "^7.13.15", "@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "^7.14.0", "@babel/preset-env": "^7.14.1",
"@babel/preset-react": "^7.13.13", "@babel/preset-react": "^7.13.13",
"@babel/preset-typescript": "^7.13.0",
"@babel/runtime": "^7.14.0", "@babel/runtime": "^7.14.0",
"babel-loader": "^8.2.2" "babel-loader": "^8.2.2",
"source-map-loader": "^2.0.1",
"typescript": "^4.2.4"
}, },
"devDependencies": { "devDependencies": {
"prettier": "^2.2.1" "prettier": "^2.3.0"
} }
} }

File diff suppressed because it is too large Load Diff