framework/js-packages/webpack-config/index.js

71 lines
1.7 KiB
JavaScript
Raw Normal View History

const fs = require('fs');
2018-02-24 13:31:59 +08:00
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']) {
2018-06-16 12:19:34 +08:00
const file = path.resolve(process.cwd(), app+'.js');
if (fs.existsSync(file)) {
entries[app] = file;
}
}
2018-06-16 12:19:34 +08:00
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', {modules: false, loose: true}],
['@babel/preset-react']
],
2018-02-24 13:31:59 +08:00
plugins: [
['@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
},
output: {
2018-06-16 12:22:07 +08:00
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.
2018-02-24 13:31:59 +08:00
function(context, request, callback) {
let matches;
if ((matches = /^flarum\/(.+)$/.exec(request))) {
2018-02-24 13:31:59 +08:00
return callback(null, 'root flarum.compat[\'' + matches[1] + '\']');
}
callback();
}
],
2018-02-24 13:31:59 +08:00
devtool: 'source-map'
};
2018-02-24 13:31:59 +08:00
};