2018-06-03 12:48:41 +08:00
|
|
|
const fs = require('fs');
|
2018-02-24 13:31:59 +08:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
|
|
|
|
module.exports = function(options = {}) {
|
2018-06-03 12:48:41 +08:00
|
|
|
return {
|
|
|
|
// 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']) {
|
2018-06-16 12:19:34 +08:00
|
|
|
const file = path.resolve(process.cwd(), app+'.js');
|
2018-06-03 12:48:41 +08:00
|
|
|
if (fs.existsSync(file)) {
|
|
|
|
entries[app] = file;
|
|
|
|
}
|
|
|
|
}
|
2018-06-16 12:19:34 +08:00
|
|
|
|
2018-06-03 12:48:41 +08:00
|
|
|
return entries;
|
|
|
|
}(),
|
|
|
|
|
2018-02-24 13:31:59 +08:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
2018-06-16 12:18:04 +08:00
|
|
|
presets: [
|
|
|
|
['@babel/preset-env', {modules: false, loose: true}],
|
|
|
|
['@babel/preset-react']
|
|
|
|
],
|
2018-02-24 13:31:59 +08:00
|
|
|
plugins: [
|
2018-06-16 12:18:04 +08:00
|
|
|
['@babel/plugin-transform-runtime', {useESModules: true}],
|
2018-02-24 13:31:59 +08:00
|
|
|
['@babel/plugin-proposal-class-properties'],
|
|
|
|
['@babel/plugin-transform-react-jsx', {pragma: 'm'}]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2018-02-24 13:59:19 +08:00
|
|
|
},
|
|
|
|
|
2018-06-03 12:48:41 +08:00
|
|
|
output: {
|
2018-06-16 12:22:07 +08:00
|
|
|
path: path.resolve(process.cwd(), 'dist'),
|
2018-06-16 12:22:53 +08:00
|
|
|
library: 'module.exports',
|
|
|
|
libraryTarget: 'assign'
|
2018-06-03 12:48:41 +08:00
|
|
|
},
|
|
|
|
|
2018-02-24 14:33:09 +08:00
|
|
|
externals: [
|
2018-06-03 12:48:41 +08:00
|
|
|
{
|
|
|
|
'@flarum/core/forum': 'flarum',
|
|
|
|
'@flarum/core/admin': 'flarum',
|
|
|
|
'jquery': 'jQuery'
|
|
|
|
},
|
|
|
|
|
|
|
|
// Support importing old-style core modules.
|
2018-02-24 13:31:59 +08:00
|
|
|
function(context, request, callback) {
|
|
|
|
let matches;
|
2018-02-24 14:33:09 +08:00
|
|
|
if ((matches = /^flarum\/(.+)$/.exec(request))) {
|
2018-02-24 13:31:59 +08:00
|
|
|
return callback(null, 'root flarum.compat[\'' + matches[1] + '\']');
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
}
|
2018-06-03 12:48:41 +08:00
|
|
|
],
|
2018-02-24 13:31:59 +08:00
|
|
|
|
2018-06-03 12:48:41 +08:00
|
|
|
devtool: 'source-map'
|
|
|
|
};
|
2018-02-24 13:31:59 +08:00
|
|
|
};
|