2017-02-10 15:18:42 +00:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
2016-02-24 10:44:14 +00:00
|
|
|
|
2017-02-12 15:29:56 +00:00
|
|
|
// Generates a path to an entry file to be compiled by Webpack.
|
2017-11-17 11:23:43 +00:00
|
|
|
const getEntryPath = (app, filename) => path.resolve('wagtail', app, 'static_src', `wagtail${app}`, 'app', filename);
|
2017-02-12 15:29:56 +00:00
|
|
|
// Generates a path to the output bundle to be loaded in the browser.
|
2017-11-17 11:23:43 +00:00
|
|
|
const getOutputPath = (app, filename) => path.join('wagtail', app, 'static', `wagtail${app}`, 'js', filename);
|
2016-02-24 10:44:14 +00:00
|
|
|
|
2018-01-17 21:23:17 +00:00
|
|
|
// Mapping from package name to exposed global variable.
|
|
|
|
const exposedDependencies = {
|
|
|
|
'focus-trap-react': 'FocusTrapReact',
|
|
|
|
'react': 'React',
|
|
|
|
'react-dom': 'ReactDOM',
|
|
|
|
'react-transition-group/CSSTransitionGroup': 'CSSTransitionGroup',
|
2018-01-17 22:07:39 +00:00
|
|
|
'draft-js': 'DraftJS',
|
|
|
|
};
|
2018-01-17 21:23:17 +00:00
|
|
|
|
2017-02-12 15:29:56 +00:00
|
|
|
module.exports = function exports() {
|
|
|
|
const entry = {
|
|
|
|
// Create a vendor chunk that will contain polyfills, and all third-party dependencies.
|
2017-06-07 13:18:44 +00:00
|
|
|
vendor: [
|
|
|
|
'./client/src/utils/polyfills.js',
|
|
|
|
],
|
2017-02-12 15:29:56 +00:00
|
|
|
};
|
2016-02-24 10:44:14 +00:00
|
|
|
|
2017-11-17 11:23:43 +00:00
|
|
|
entry[getOutputPath('admin', 'wagtailadmin')] = getEntryPath('admin', 'wagtailadmin.entry.js');
|
2017-12-05 17:50:20 +00:00
|
|
|
entry[getOutputPath('admin', 'draftail')] = getEntryPath('admin', 'draftail.entry.js');
|
2016-02-24 10:44:14 +00:00
|
|
|
|
|
|
|
return {
|
2017-02-12 15:29:56 +00:00
|
|
|
entry: entry,
|
2016-02-24 10:44:14 +00:00
|
|
|
output: {
|
2017-06-07 09:39:24 +00:00
|
|
|
path: path.resolve('.'),
|
2016-02-24 10:44:14 +00:00
|
|
|
filename: '[name].js',
|
|
|
|
publicPath: '/static/js/'
|
|
|
|
},
|
|
|
|
plugins: [
|
2017-02-12 15:29:56 +00:00
|
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
|
|
name: 'vendor',
|
2017-11-17 11:23:43 +00:00
|
|
|
filename: getOutputPath('admin', '[name].js'),
|
2018-01-17 22:07:39 +00:00
|
|
|
minChunks: 2,
|
2017-02-12 15:29:56 +00:00
|
|
|
}),
|
2016-02-24 10:44:14 +00:00
|
|
|
],
|
2017-02-12 15:29:56 +00:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'wagtail-client': path.resolve('.', 'client'),
|
|
|
|
},
|
|
|
|
},
|
2016-02-24 10:44:14 +00:00
|
|
|
module: {
|
2017-06-07 09:39:24 +00:00
|
|
|
rules: [
|
2016-02-24 10:44:14 +00:00
|
|
|
{
|
2017-02-10 15:18:42 +00:00
|
|
|
test: /\.js$/,
|
2017-06-07 09:39:24 +00:00
|
|
|
loader: 'babel-loader',
|
2017-05-28 18:49:05 +00:00
|
|
|
exclude: /node_modules/,
|
2016-02-24 10:44:14 +00:00
|
|
|
},
|
2018-01-17 21:23:17 +00:00
|
|
|
].concat(Object.keys(exposedDependencies).map((name) => {
|
2018-01-18 17:06:04 +00:00
|
|
|
const globalName = exposedDependencies[name];
|
|
|
|
|
2018-01-17 21:23:17 +00:00
|
|
|
// Create expose-loader configs for each Wagtail dependency.
|
|
|
|
return {
|
|
|
|
test: require.resolve(name),
|
2018-01-18 17:06:04 +00:00
|
|
|
use: [
|
|
|
|
{
|
2018-01-17 21:23:17 +00:00
|
|
|
loader: 'expose-loader',
|
2018-01-18 17:06:04 +00:00
|
|
|
options: globalName,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2018-01-17 21:23:17 +00:00
|
|
|
}))
|
2017-02-12 15:29:56 +00:00
|
|
|
},
|
2018-02-17 12:54:06 +00:00
|
|
|
|
|
|
|
// See https://webpack.js.org/configuration/devtool/.
|
|
|
|
devtool: 'source-map',
|
|
|
|
|
2017-02-12 15:29:56 +00:00
|
|
|
stats: {
|
|
|
|
// Add chunk information (setting this to `false` allows for a less verbose output)
|
|
|
|
chunks: false,
|
|
|
|
// Add the hash of the compilation
|
|
|
|
hash: false,
|
|
|
|
// `webpack --colors` equivalent
|
|
|
|
colors: true,
|
|
|
|
// Add information about the reasons why modules are included
|
|
|
|
reasons: false,
|
|
|
|
// Add webpack version information
|
|
|
|
version: false,
|
2017-06-07 13:29:58 +00:00
|
|
|
// Set the maximum number of modules to be shown
|
|
|
|
maxModules: 0,
|
2017-02-12 15:29:56 +00:00
|
|
|
},
|
2017-06-07 13:21:12 +00:00
|
|
|
// Some libraries import Node modules but don't use them in the browser.
|
|
|
|
// Tell Webpack to provide empty mocks for them so importing them works.
|
|
|
|
node: {
|
|
|
|
fs: 'empty',
|
|
|
|
net: 'empty',
|
|
|
|
tls: 'empty',
|
|
|
|
},
|
2016-02-24 10:44:14 +00:00
|
|
|
};
|
|
|
|
};
|