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

79 lines
2.0 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']) {
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
},
output: {
path: path.resolve(process.cwd(), 'js')
},
2018-02-24 13:59:19 +08:00
// For backwards compatibility, search for non-relative-path modules
// in the source directories. Also make sure the root node_modules
// directory is searched.
2018-02-24 13:59:19 +08:00
resolve: {
modules: [
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 13:31:59 +08:00
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
};