framework/js-packages/webpack-config/index.js
2018-06-16 13:52:53 +09:30

71 lines
1.7 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
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 = {};
for (const app of ['forum', 'admin']) {
const file = path.resolve(process.cwd(), app+'.js');
if (fs.existsSync(file)) {
entries[app] = file;
}
}
return entries;
}(),
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {modules: false, loose: true}],
['@babel/preset-react']
],
plugins: [
['@babel/plugin-transform-runtime', {useESModules: true}],
['@babel/plugin-proposal-class-properties'],
['@babel/plugin-transform-react-jsx', {pragma: 'm'}]
]
}
}
}
]
},
output: {
path: path.resolve(process.cwd(), 'dist'),
library: 'module.exports',
libraryTarget: 'assign'
},
externals: [
{
'@flarum/core/forum': 'flarum',
'@flarum/core/admin': 'flarum',
'jquery': 'jQuery'
},
// Support importing old-style core modules.
function(context, request, callback) {
let matches;
if ((matches = /^flarum\/(.+)$/.exec(request))) {
return callback(null, 'root flarum.compat[\'' + matches[1] + '\']');
}
callback();
}
],
devtool: 'source-map'
};
};