mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 09:41:49 +08:00
Move Typescript configuration to webpack config from core (#11)
This commit is contained in:
parent
3610f08d6b
commit
4bdb02a878
|
@ -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).
|
||||
|
||||
## 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
|
||||
|
||||
### `useExtensions`
|
||||
|
@ -34,6 +40,6 @@ import { Tag } from '@flarum/tags/forum';
|
|||
|
||||
```js
|
||||
module.exports = config({
|
||||
useExtensions: ['flarum/tags']
|
||||
useExtensions: ['flarum/tags'],
|
||||
});
|
||||
```
|
||||
|
|
|
@ -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,
|
||||
}],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
10924
js-packages/webpack-config/package-lock.json
generated
10924
js-packages/webpack-config/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -6,7 +6,7 @@
|
|||
"author": "Flarum Team",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"webpack": "^4.0.0"
|
||||
"webpack": "^4.46.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.14.0",
|
||||
|
@ -15,12 +15,15 @@
|
|||
"@babel/plugin-transform-object-assign": "^7.12.13",
|
||||
"@babel/plugin-transform-react-jsx": "^7.13.12",
|
||||
"@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-typescript": "^7.13.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": {
|
||||
"prettier": "^2.2.1"
|
||||
"prettier": "^2.3.0"
|
||||
}
|
||||
}
|
||||
|
|
1522
js-packages/webpack-config/yarn.lock
Normal file
1522
js-packages/webpack-config/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user