2017-02-10 16:18:42 +01:00
|
|
|
|
const path = require('path');
|
2016-02-24 11:44:14 +01:00
|
|
|
|
|
2017-02-12 16:29:56 +01:00
|
|
|
|
// Generates a path to an entry file to be compiled by Webpack.
|
2017-11-17 12:23:43 +01:00
|
|
|
|
const getEntryPath = (app, filename) => path.resolve('wagtail', app, 'static_src', `wagtail${app}`, 'app', filename);
|
2017-02-12 16:29:56 +01:00
|
|
|
|
// Generates a path to the output bundle to be loaded in the browser.
|
2017-11-17 12:23:43 +01:00
|
|
|
|
const getOutputPath = (app, filename) => path.join('wagtail', app, 'static', `wagtail${app}`, 'js', filename);
|
2016-02-24 11:44:14 +01:00
|
|
|
|
|
2018-01-17 22:23:17 +01: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 23:07:39 +01:00
|
|
|
|
'draft-js': 'DraftJS',
|
|
|
|
|
};
|
2018-01-17 22:23:17 +01:00
|
|
|
|
|
2017-02-12 16:29:56 +01:00
|
|
|
|
module.exports = function exports() {
|
2020-05-29 01:39:20 +02:00
|
|
|
|
const entry = {};
|
|
|
|
|
|
2020-06-04 09:10:47 +02:00
|
|
|
|
entry[getOutputPath('admin', 'wagtailadmin')] = [
|
|
|
|
|
'./client/src/utils/polyfills.js',
|
|
|
|
|
getEntryPath('admin', 'wagtailadmin.entry.js'),
|
|
|
|
|
];
|
|
|
|
|
entry[getOutputPath('admin', 'draftail')] = [
|
|
|
|
|
'./client/src/utils/polyfills.js',
|
|
|
|
|
getEntryPath('admin', 'draftail.entry.js'),
|
|
|
|
|
];
|
2016-02-24 11:44:14 +01:00
|
|
|
|
|
|
|
|
|
return {
|
2017-02-12 16:29:56 +01:00
|
|
|
|
entry: entry,
|
2016-02-24 11:44:14 +01:00
|
|
|
|
output: {
|
2017-06-07 11:39:24 +02:00
|
|
|
|
path: path.resolve('.'),
|
2016-02-24 11:44:14 +01:00
|
|
|
|
filename: '[name].js',
|
|
|
|
|
publicPath: '/static/js/'
|
|
|
|
|
},
|
2017-02-12 16:29:56 +01:00
|
|
|
|
resolve: {
|
2020-10-21 01:51:09 +02:00
|
|
|
|
extensions: ['.ts', '.tsx', '.js'],
|
2017-02-12 16:29:56 +01:00
|
|
|
|
},
|
2016-02-24 11:44:14 +01:00
|
|
|
|
module: {
|
2017-06-07 11:39:24 +02:00
|
|
|
|
rules: [
|
2016-02-24 11:44:14 +01:00
|
|
|
|
{
|
2020-10-21 01:51:09 +02:00
|
|
|
|
test: /\.(js|ts)x?$/,
|
2020-10-21 10:42:14 +02:00
|
|
|
|
loader: 'ts-loader',
|
2017-05-28 20:49:05 +02:00
|
|
|
|
exclude: /node_modules/,
|
2016-02-24 11:44:14 +01:00
|
|
|
|
},
|
2018-01-17 22:23:17 +01:00
|
|
|
|
].concat(Object.keys(exposedDependencies).map((name) => {
|
2018-01-18 18:06:04 +01:00
|
|
|
|
const globalName = exposedDependencies[name];
|
|
|
|
|
|
2018-01-17 22:23:17 +01:00
|
|
|
|
// Create expose-loader configs for each Wagtail dependency.
|
|
|
|
|
return {
|
|
|
|
|
test: require.resolve(name),
|
2018-01-18 18:06:04 +01:00
|
|
|
|
use: [
|
|
|
|
|
{
|
2018-01-17 22:23:17 +01:00
|
|
|
|
loader: 'expose-loader',
|
2018-01-18 18:06:04 +01:00
|
|
|
|
options: globalName,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
2018-01-17 22:23:17 +01:00
|
|
|
|
}))
|
2017-02-12 16:29:56 +01:00
|
|
|
|
},
|
2018-02-17 13:54:06 +01:00
|
|
|
|
|
2020-05-29 01:39:20 +02:00
|
|
|
|
optimization: {
|
|
|
|
|
splitChunks: {
|
|
|
|
|
cacheGroups: {
|
|
|
|
|
vendor: {
|
|
|
|
|
name: getOutputPath('admin', 'vendor'),
|
|
|
|
|
chunks: 'initial',
|
|
|
|
|
minChunks: 2,
|
|
|
|
|
reuseExistingChunk: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2018-02-17 13:54:06 +01:00
|
|
|
|
// See https://webpack.js.org/configuration/devtool/.
|
|
|
|
|
devtool: 'source-map',
|
|
|
|
|
|
2020-05-28 18:43:06 +02:00
|
|
|
|
// For development mode only.
|
|
|
|
|
watchOptions: {
|
|
|
|
|
poll: 1000,
|
|
|
|
|
aggregateTimeout: 300,
|
|
|
|
|
},
|
|
|
|
|
|
2020-10-21 11:00:45 +02:00
|
|
|
|
// Disable performance hints – currently there are much more valuable
|
|
|
|
|
// optimizations for us to do outside of Webpack
|
|
|
|
|
performance: {
|
|
|
|
|
hints: false
|
|
|
|
|
},
|
|
|
|
|
|
2017-02-12 16:29:56 +01: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 15:29:58 +02:00
|
|
|
|
// Set the maximum number of modules to be shown
|
|
|
|
|
maxModules: 0,
|
2017-02-12 16:29:56 +01:00
|
|
|
|
},
|
2017-06-07 15:21:12 +02: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 11:44:14 +01:00
|
|
|
|
};
|
|
|
|
|
};
|