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']) {
|
|
|
|
const file = path.resolve(process.cwd(), 'js/' + app + '/index.js');
|
|
|
|
if (fs.existsSync(file)) {
|
|
|
|
entries[app] = file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return entries;
|
|
|
|
}(),
|
|
|
|
|
2018-02-24 13:31:59 +08:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
presets: ['@babel/preset-env', '@babel/preset-react'],
|
|
|
|
plugins: [
|
|
|
|
['@babel/plugin-transform-runtime'],
|
|
|
|
['@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: {
|
|
|
|
path: path.resolve(process.cwd(), 'js')
|
|
|
|
},
|
|
|
|
|
2018-02-24 13:59:19 +08:00
|
|
|
// For backwards compatibility, search for non-relative-path modules
|
2018-06-03 12:48:41 +08:00
|
|
|
// in the source directories. Also make sure the root node_modules
|
|
|
|
// directory is searched.
|
2018-02-24 13:59:19 +08:00
|
|
|
resolve: {
|
|
|
|
modules: [
|
2018-06-03 12:48:41 +08:00
|
|
|
path.resolve(process.cwd(), 'js/forum'),
|
|
|
|
path.resolve(process.cwd(), 'js/admin'),
|
|
|
|
path.resolve(process.cwd(), 'js/common'),
|
2018-02-24 13:59:19 +08:00
|
|
|
path.resolve(process.cwd(), 'node_modules'),
|
|
|
|
'node_modules'
|
|
|
|
]
|
2018-02-24 14:33:09 +08:00
|
|
|
},
|
2018-02-24 13:31:59 +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
|
|
|
};
|