2017-02-10 15:18:42 +00:00
|
|
|
const path = require('path');
|
2016-02-24 10:44:14 +00:00
|
|
|
|
2017-02-12 15:29:56 +00:00
|
|
|
// Generates a path to the output bundle to be loaded in the browser.
|
2021-01-05 19:24:40 +00:00
|
|
|
const getOutputPath = (app, filename) => {
|
2021-01-07 16:36:43 +00:00
|
|
|
let appLabel = `wagtail${app}`;
|
|
|
|
|
|
|
|
// Exceptions
|
|
|
|
if (app === 'documents') {
|
|
|
|
appLabel = 'wagtaildocs';
|
|
|
|
} else if (app === 'contrib/table_block') {
|
|
|
|
appLabel = 'table_block';
|
2021-08-27 12:57:34 +00:00
|
|
|
} else if (app === 'contrib/typed_table_block') {
|
|
|
|
appLabel = 'typed_table_block';
|
2021-01-07 16:36:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 19:24:40 +00:00
|
|
|
return path.join('wagtail', app, 'static', appLabel, '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() {
|
2021-01-05 14:24:30 +00:00
|
|
|
const entrypoints = {
|
2021-01-07 16:36:43 +00:00
|
|
|
'admin': [
|
2021-08-30 15:33:43 +00:00
|
|
|
'collapsible',
|
2020-12-04 11:13:45 +00:00
|
|
|
'comments',
|
2021-01-05 14:24:30 +00:00
|
|
|
'core',
|
|
|
|
'date-time-chooser',
|
|
|
|
'draftail',
|
2022-01-15 01:00:02 +00:00
|
|
|
'expanding-formset',
|
2021-01-05 14:24:30 +00:00
|
|
|
'filtered-select',
|
|
|
|
'hallo-bootstrap',
|
|
|
|
'hallo-plugins/hallo-hr',
|
|
|
|
'hallo-plugins/hallo-requireparagraphs',
|
|
|
|
'hallo-plugins/hallo-wagtaillink',
|
|
|
|
'lock-unlock-action',
|
|
|
|
'modal-workflow',
|
|
|
|
'page-chooser-modal',
|
|
|
|
'page-chooser',
|
|
|
|
'page-editor',
|
|
|
|
'privacy-switch',
|
2021-05-10 16:09:47 +00:00
|
|
|
'sidebar',
|
2021-05-10 14:58:51 +00:00
|
|
|
'sidebar-legacy',
|
2021-01-05 14:24:30 +00:00
|
|
|
'task-chooser-modal',
|
|
|
|
'task-chooser',
|
2020-11-30 17:56:57 +00:00
|
|
|
'telepath/blocks',
|
|
|
|
'telepath/telepath',
|
|
|
|
'telepath/widgets',
|
2021-01-05 14:24:30 +00:00
|
|
|
'userbar',
|
|
|
|
'wagtailadmin',
|
|
|
|
'workflow-action',
|
|
|
|
'workflow-status',
|
2021-03-23 12:58:35 +00:00
|
|
|
'bulk-actions'
|
2021-01-05 14:24:30 +00:00
|
|
|
],
|
2021-01-07 16:36:43 +00:00
|
|
|
'images': [
|
2021-01-05 15:11:40 +00:00
|
|
|
'image-chooser',
|
2021-01-08 12:51:19 +00:00
|
|
|
'image-chooser-telepath',
|
2021-01-05 19:24:40 +00:00
|
|
|
],
|
2021-01-07 16:36:43 +00:00
|
|
|
'documents': [
|
2021-01-05 19:24:40 +00:00
|
|
|
'document-chooser',
|
2021-01-08 14:29:32 +00:00
|
|
|
'document-chooser-telepath',
|
2021-01-05 19:24:40 +00:00
|
|
|
],
|
2021-01-07 16:36:43 +00:00
|
|
|
'snippets': [
|
2021-01-06 12:26:05 +00:00
|
|
|
'snippet-chooser',
|
2021-01-08 15:12:41 +00:00
|
|
|
'snippet-chooser-telepath',
|
2021-01-06 12:26:05 +00:00
|
|
|
],
|
2021-01-07 16:36:43 +00:00
|
|
|
'contrib/table_block': [
|
|
|
|
'table',
|
|
|
|
],
|
2021-08-27 12:57:34 +00:00
|
|
|
'contrib/typed_table_block': [
|
|
|
|
'typed_table_block',
|
|
|
|
],
|
2021-01-05 14:24:30 +00:00
|
|
|
};
|
2020-12-04 09:47:38 +00:00
|
|
|
|
2020-12-04 11:34:26 +00:00
|
|
|
const entry = {};
|
2021-01-05 14:24:30 +00:00
|
|
|
for (const [appName, moduleNames] of Object.entries(entrypoints)) {
|
|
|
|
moduleNames.forEach(moduleName => {
|
2020-12-27 17:53:41 +00:00
|
|
|
entry[moduleName] = {
|
2020-12-27 18:36:48 +00:00
|
|
|
import: [`./client/src/entrypoints/${appName}/${moduleName}.js`],
|
2020-12-27 17:53:41 +00:00
|
|
|
filename: getOutputPath(appName, moduleName) + '.js',
|
|
|
|
};
|
2020-12-27 18:36:48 +00:00
|
|
|
|
|
|
|
// Add polyfills to all bundles except userbar
|
|
|
|
// polyfills.js imports from node_modules, which adds a dependency on vendor.js (produced by splitChunks)
|
|
|
|
// Because userbar is supposed to run on peoples frontends, we code it using portable JS so we don't need
|
|
|
|
// to pull in all the additional JS that the vendor bundle has (such as React).
|
|
|
|
if (moduleName !== 'userbar') {
|
|
|
|
entry[moduleName].import.push('./client/src/utils/polyfills.js');
|
|
|
|
}
|
2021-01-05 14:24:30 +00:00
|
|
|
});
|
|
|
|
}
|
2020-12-04 09:47:38 +00:00
|
|
|
|
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
|
|
|
publicPath: '/static/js/'
|
|
|
|
},
|
2017-02-12 15:29:56 +00:00
|
|
|
resolve: {
|
2020-10-20 23:51:09 +00:00
|
|
|
extensions: ['.ts', '.tsx', '.js'],
|
2020-12-27 17:53:41 +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.
|
|
|
|
fallback: {
|
|
|
|
fs: false,
|
|
|
|
net: false,
|
|
|
|
tls: false,
|
|
|
|
},
|
2017-02-12 15:29:56 +00:00
|
|
|
},
|
2020-12-21 14:58:12 +00:00
|
|
|
externals: {
|
|
|
|
jquery: 'jQuery',
|
|
|
|
},
|
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
|
|
|
{
|
2020-10-20 23:51:09 +00:00
|
|
|
test: /\.(js|ts)x?$/,
|
2020-10-21 08:42:14 +00:00
|
|
|
loader: 'ts-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',
|
2020-12-27 17:53:41 +00:00
|
|
|
options: {
|
2020-12-04 11:13:45 +00:00
|
|
|
exposes: {
|
|
|
|
globalName,
|
|
|
|
override: true
|
|
|
|
}
|
2020-12-27 17:53:41 +00:00
|
|
|
},
|
2018-01-18 17:06:04 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2018-01-17 21:23:17 +00:00
|
|
|
}))
|
2017-02-12 15:29:56 +00:00
|
|
|
},
|
2018-02-17 12:54:06 +00:00
|
|
|
|
2020-05-28 23:39:20 +00:00
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
vendor: {
|
|
|
|
name: getOutputPath('admin', 'vendor'),
|
|
|
|
chunks: 'initial',
|
|
|
|
minChunks: 2,
|
|
|
|
reuseExistingChunk: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2018-02-17 12:54:06 +00:00
|
|
|
// See https://webpack.js.org/configuration/devtool/.
|
|
|
|
devtool: 'source-map',
|
|
|
|
|
2020-05-28 16:43:06 +00:00
|
|
|
// For development mode only.
|
|
|
|
watchOptions: {
|
|
|
|
poll: 1000,
|
|
|
|
aggregateTimeout: 300,
|
|
|
|
},
|
|
|
|
|
2020-10-21 09:00:45 +00:00
|
|
|
// Disable performance hints – currently there are much more valuable
|
|
|
|
// optimizations for us to do outside of Webpack
|
|
|
|
performance: {
|
|
|
|
hints: false
|
|
|
|
},
|
|
|
|
|
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:21:12 +00:00
|
|
|
},
|
2016-02-24 10:44:14 +00:00
|
|
|
};
|
|
|
|
};
|