bring local dev flarum-webpack-config to core for easier development

This commit is contained in:
David Sevilla Martin 2020-03-07 10:15:47 -05:00
parent 8ea7f9bc17
commit 4910205dc7
No known key found for this signature in database
GPG Key ID: F764F1417E16B15F
8 changed files with 1909 additions and 593 deletions

2271
js/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,23 +5,18 @@
"bootstrap": "^3.4.1",
"classnames": "^2.2.6",
"color-thief-browser": "^2.0.2",
"dayjs": "^1.8.16",
"expose-loader": "^0.7.5",
"dayjs": "^1.8.20",
"flarum-webpack-config": "^0.1.0-beta.10",
"hc-sticky": "^2.2.3",
"imports-loader": "^0.8.0",
"jump.js": "^1.0.2",
"lodash-es": "^4.17.15",
"m.attrs.bidi": "github:tobscure/m.attrs.bidi",
"micromodal": "^0.4.2",
"mithril": "^2.0.4",
"mousetrap": "^1.6.3",
"mousetrap": "^1.6.5",
"punycode": "^2.1.1",
"spin.js": "^4.0.0",
"tooltip.js": "^1.3.2",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.8",
"webpack-merge": "^4.2.2",
"spin.js": "^4.1.0",
"tooltip.js": "^1.3.3",
"zepto": "^1.2.0"
},
"scripts": {
@ -30,8 +25,29 @@
"lint": "prettier --single-quote --trailing-comma es5 --print-width 150 --tab-width 4 --write \"src/**/*\" \"*.{ts,js}\""
},
"devDependencies": {
"@babel/core": "^7.8.7",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-object-assign": "^7.8.3",
"@babel/plugin-transform-react-jsx": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.7",
"@babel/preset-react": "^7.8.3",
"@babel/preset-typescript": "^7.8.3",
"@babel/runtime": "^7.8.7",
"@types/classnames": "^2.2.9",
"@types/mithril": "^2.0.2",
"@types/zepto": "^1.0.30",
"prettier": "^1.19.1"
"babel-loader": "^8.0.6",
"expose-loader": "^0.7.5",
"friendly-errors-webpack-plugin": "^1.7.0",
"imports-loader": "^0.8.0",
"prettier": "^1.19.1",
"source-map-loader": "^0.2.4",
"typescript": "^3.8.3",
"webpack": "^4.42.0",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-cli": "^3.3.11",
"webpack-merge": "^4.2.2"
}
}

2
js/shims.d.ts vendored
View File

@ -1,4 +1,4 @@
import 'flarum-webpack-config/shims';
export * from './webpack-flarum-shims';
import Forum from './src/forum/Forum';

View File

@ -1,3 +1,3 @@
{
"extends": "flarum-webpack-config/tsconfig.json"
"extends": "./webpack-flarum-tsconfig"
}

148
js/webpack-flarum-config.js Normal file
View File

@ -0,0 +1,148 @@
// TEMPORARY
// This will go in flarum-webpack-config when ready
// In core for development purposes
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const plugins = [new FriendlyErrorsPlugin()];
// add production plugins
if (process.env.NODE_ENV === 'production') {
plugins.push(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false,
},
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
})
);
}
// if --analyze is found in command arguments,
// run webpack bundle analyzer to analyze dependencies
// and the space they take up
if (process.argv.includes('--analyze')) {
plugins.push(new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)());
}
module.exports = (options = {}) => {
return {
devtool: 'source-map',
watchOptions: {
aggregateTimeout: 300,
poll: 1000,
},
// Set up entry points for each of the forum + admin apps, but only
// if they exist.
entry: (function() {
const entries = {};
for (const app of ['forum', 'admin']) {
const file = path.resolve(process.cwd(), app + '.ts');
if (fs.existsSync(file)) {
entries[app] = file;
}
}
return entries;
})(),
output: {
path: path.resolve(process.cwd(), './dist'),
publicPath: '/dist/',
library: 'module.exports',
libraryTarget: 'assign',
devtoolNamespace: require(path.resolve(process.cwd(), 'package.json')).name,
},
module: {
rules: [
{
test: /\.js$/,
enforce: 'pre',
loader: 'source-map-loader',
},
{
test: /\.(js|jsx|tsx|ts)$/,
exclude: /node_modules\/(?!babel-runtime)/,
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
modules: false,
loose: true,
targets: {
browsers: ['> 1%', 'last 2 versions', 'not ie <= 8', 'ie >= 11'],
},
},
],
['@babel/preset-typescript'],
['@babel/preset-react'],
],
plugins: [
['@babel/plugin-transform-runtime', { useESModules: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-transform-react-jsx', { pragma: 'm' }],
['@babel/plugin-transform-object-assign'],
['@babel/plugin-syntax-dynamic-import'],
['@babel/plugin-proposal-optional-chaining'],
],
},
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
externals: [
{
mithril: 'm',
},
(function() {
const externals = {};
if (options.useExtensions) {
for (const extension of options.useExtensions) {
externals['@' + extension] = externals['@' + extension + '/forum'] = externals['@' + extension + '/admin'] =
"flarum.extensions['" + extension + "']";
}
}
return externals;
})(),
// Support importing old-style core modules.
function(context, request, callback) {
const matches = /^flarum\/(.+?)(?:\/(.+))?$/.exec(request);
if (matches) {
const lib = matches[2] ? `flarum.core.compat['${matches[2]}']` : 'flarum.core.compat';
return callback(null, `root ${lib}`);
}
callback();
},
],
plugins,
};
};

19
js/webpack-flarum-shims.d.ts vendored Normal file
View File

@ -0,0 +1,19 @@
import * as Mithril from 'mithril';
import Stream from 'mithril/stream';
import * as _dayjs from 'dayjs';
import classNames from 'classnames';
interface m extends Mithril.Static {
prop: Stream.Static;
}
declare global {
const m: m;
const dayjs: typeof _dayjs;
const classNames: classNames;
}
export as namespace Mithril;
export {};

View File

@ -0,0 +1,21 @@
{
"include": ["src/**/*.ts"],
"files": ["shims.d.ts"],
"compilerOptions": {
"allowUmdGlobalAccess": true,
"outDir": "dist",
"sourceMap": true,
"strict": true,
"noImplicitReturns": false,
"noImplicitAny": false,
"module": "es2015",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"moduleResolution": "node",
"target": "es6",
"jsx": "preserve",
"lib": ["es2015", "es2017", "dom"],
"allowSyntheticDefaultImports": true
}
}

View File

@ -1,5 +1,4 @@
const config = require('flarum-webpack-config');
const webpack = require('webpack');
const config = require('./webpack-flarum-config');
const merge = require('webpack-merge');
module.exports = merge(config(), {