2017-02-10 16:18:42 +01:00
|
|
|
|
const path = require('path');
|
2021-12-23 05:21:23 +01:00
|
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2016-02-24 11:44:14 +01:00
|
|
|
|
|
2017-02-12 16:29:56 +01:00
|
|
|
|
// Generates a path to the output bundle to be loaded in the browser.
|
2021-12-23 05:21:23 +01:00
|
|
|
|
const getOutputPath = (app, folder, filename) => {
|
|
|
|
|
const exceptions = {
|
|
|
|
|
'documents': 'wagtaildocs',
|
|
|
|
|
'contrib/table_block': 'table_block',
|
|
|
|
|
'contrib/typed_table_block': 'typed_table_block',
|
|
|
|
|
'contrib/styleguide': 'wagtailstyleguide',
|
|
|
|
|
'contrib/modeladmin': 'wagtailmodeladmin',
|
2021-01-07 17:36:43 +01:00
|
|
|
|
};
|
|
|
|
|
|
2021-12-23 05:21:23 +01:00
|
|
|
|
const appLabel = exceptions[app] || `wagtail${app}`;
|
|
|
|
|
|
|
|
|
|
return path.join('wagtail', app, 'static', appLabel, folder, filename);
|
2021-01-05 20:24:40 +01:00
|
|
|
|
};
|
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
|
|
|
|
|
2021-12-23 05:21:23 +01:00
|
|
|
|
module.exports = function exports(env, argv) {
|
|
|
|
|
const isProduction = argv.mode === 'production';
|
|
|
|
|
|
2021-01-05 15:24:30 +01:00
|
|
|
|
const entrypoints = {
|
2021-01-07 17:36:43 +01:00
|
|
|
|
'admin': [
|
2022-05-20 17:42:43 +02:00
|
|
|
|
'chooser-modal',
|
2022-06-09 11:42:37 +02:00
|
|
|
|
'chooser-widget',
|
2022-07-06 17:12:25 +02:00
|
|
|
|
'chooser-widget-telepath',
|
2020-12-04 12:13:45 +01:00
|
|
|
|
'comments',
|
2021-01-05 15:24:30 +01:00
|
|
|
|
'core',
|
|
|
|
|
'date-time-chooser',
|
|
|
|
|
'draftail',
|
2022-01-15 02:00:02 +01:00
|
|
|
|
'expanding-formset',
|
2021-01-05 15:24:30 +01:00
|
|
|
|
'filtered-select',
|
|
|
|
|
'lock-unlock-action',
|
|
|
|
|
'modal-workflow',
|
|
|
|
|
'page-chooser-modal',
|
|
|
|
|
'page-chooser',
|
|
|
|
|
'page-editor',
|
2022-07-14 14:59:05 +02:00
|
|
|
|
'preview-panel',
|
2021-01-05 15:24:30 +01:00
|
|
|
|
'privacy-switch',
|
2021-05-10 18:09:47 +02:00
|
|
|
|
'sidebar',
|
2021-01-05 15:24:30 +01:00
|
|
|
|
'task-chooser-modal',
|
|
|
|
|
'task-chooser',
|
2020-11-30 18:56:57 +01:00
|
|
|
|
'telepath/blocks',
|
|
|
|
|
'telepath/telepath',
|
|
|
|
|
'telepath/widgets',
|
2021-01-05 15:24:30 +01:00
|
|
|
|
'userbar',
|
|
|
|
|
'wagtailadmin',
|
|
|
|
|
'workflow-action',
|
|
|
|
|
'workflow-status',
|
2021-03-23 13:58:35 +01:00
|
|
|
|
'bulk-actions',
|
2021-08-27 14:57:34 +02:00
|
|
|
|
],
|
2022-04-12 17:11:08 +02:00
|
|
|
|
'images': [
|
|
|
|
|
'image-chooser',
|
|
|
|
|
'image-chooser-modal',
|
|
|
|
|
'image-chooser-telepath',
|
|
|
|
|
],
|
|
|
|
|
'documents': [
|
|
|
|
|
'document-chooser',
|
|
|
|
|
'document-chooser-modal',
|
|
|
|
|
'document-chooser-telepath',
|
|
|
|
|
],
|
2022-06-20 18:53:48 +02:00
|
|
|
|
'snippets': ['snippet-chooser', 'snippet-chooser-telepath'],
|
2021-12-23 05:21:23 +01:00
|
|
|
|
'contrib/table_block': ['table'],
|
|
|
|
|
'contrib/typed_table_block': ['typed_table_block'],
|
2021-01-05 15:24:30 +01:00
|
|
|
|
};
|
2020-12-04 10:47:38 +01:00
|
|
|
|
|
2020-12-04 12:34:26 +01:00
|
|
|
|
const entry = {};
|
2022-05-20 17:08:13 +02:00
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2021-01-05 15:24:30 +01:00
|
|
|
|
for (const [appName, moduleNames] of Object.entries(entrypoints)) {
|
|
|
|
|
moduleNames.forEach((moduleName) => {
|
2020-12-27 18:53:41 +01:00
|
|
|
|
entry[moduleName] = {
|
2020-12-27 19:36:48 +01:00
|
|
|
|
import: [`./client/src/entrypoints/${appName}/${moduleName}.js`],
|
2021-12-23 05:21:23 +01:00
|
|
|
|
filename: getOutputPath(appName, 'js', moduleName) + '.js',
|
2020-12-27 18:53:41 +01:00
|
|
|
|
};
|
2021-01-05 15:24:30 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
2020-12-04 10:47:38 +01:00
|
|
|
|
|
2021-12-23 05:21:23 +01:00
|
|
|
|
const sassEntry = {};
|
|
|
|
|
sassEntry[getOutputPath('admin', 'css', 'core')] = path.resolve(
|
|
|
|
|
'wagtail',
|
|
|
|
|
'admin',
|
|
|
|
|
'static_src',
|
|
|
|
|
'wagtailadmin',
|
|
|
|
|
'scss',
|
|
|
|
|
'core.scss',
|
|
|
|
|
);
|
|
|
|
|
sassEntry[getOutputPath('admin', 'css', 'panels/draftail')] = path.resolve(
|
|
|
|
|
'wagtail',
|
|
|
|
|
'admin',
|
|
|
|
|
'static_src',
|
|
|
|
|
'wagtailadmin',
|
|
|
|
|
'scss',
|
|
|
|
|
'panels',
|
|
|
|
|
'draftail.scss',
|
|
|
|
|
);
|
|
|
|
|
sassEntry[getOutputPath('admin', 'css', 'panels/streamfield')] = path.resolve(
|
|
|
|
|
'wagtail',
|
|
|
|
|
'admin',
|
|
|
|
|
'static_src',
|
|
|
|
|
'wagtailadmin',
|
|
|
|
|
'scss',
|
|
|
|
|
'panels',
|
|
|
|
|
'streamfield.scss',
|
|
|
|
|
);
|
|
|
|
|
sassEntry[getOutputPath('admin', 'css', 'userbar')] = path.resolve(
|
|
|
|
|
'wagtail',
|
|
|
|
|
'admin',
|
|
|
|
|
'static_src',
|
|
|
|
|
'wagtailadmin',
|
|
|
|
|
'scss',
|
|
|
|
|
'userbar.scss',
|
|
|
|
|
);
|
|
|
|
|
sassEntry[getOutputPath('contrib/styleguide', 'css', 'styleguide')] =
|
|
|
|
|
path.resolve(
|
|
|
|
|
'wagtail',
|
|
|
|
|
'contrib',
|
|
|
|
|
'styleguide',
|
|
|
|
|
'static_src',
|
|
|
|
|
'wagtailstyleguide',
|
|
|
|
|
'scss',
|
|
|
|
|
'styleguide.scss',
|
|
|
|
|
);
|
|
|
|
|
sassEntry[
|
|
|
|
|
getOutputPath('contrib/typed_table_block', 'css', 'typed_table_block')
|
|
|
|
|
] = path.resolve(
|
|
|
|
|
'wagtail',
|
|
|
|
|
'contrib',
|
|
|
|
|
'typed_table_block',
|
|
|
|
|
'static_src',
|
|
|
|
|
'typed_table_block',
|
|
|
|
|
'scss',
|
|
|
|
|
'typed_table_block.scss',
|
|
|
|
|
);
|
|
|
|
|
|
2016-02-24 11:44:14 +01:00
|
|
|
|
return {
|
2021-12-23 05:21:23 +01:00
|
|
|
|
entry: {
|
|
|
|
|
...entry,
|
|
|
|
|
...sassEntry,
|
|
|
|
|
},
|
2016-02-24 11:44:14 +01:00
|
|
|
|
output: {
|
2017-06-07 11:39:24 +02:00
|
|
|
|
path: path.resolve('.'),
|
2021-12-23 05:21:23 +01:00
|
|
|
|
publicPath: '/static/',
|
2016-02-24 11:44:14 +01:00
|
|
|
|
},
|
2017-02-12 16:29:56 +01:00
|
|
|
|
resolve: {
|
2020-10-21 01:51:09 +02:00
|
|
|
|
extensions: ['.ts', '.tsx', '.js'],
|
2020-12-27 18:53:41 +01: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 16:29:56 +01:00
|
|
|
|
},
|
2020-12-21 15:58:12 +01:00
|
|
|
|
externals: {
|
|
|
|
|
jquery: 'jQuery',
|
|
|
|
|
},
|
2021-12-23 05:21:23 +01:00
|
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
|
filename: '[name].css',
|
|
|
|
|
}),
|
|
|
|
|
new CopyPlugin({
|
|
|
|
|
patterns: [
|
|
|
|
|
{
|
|
|
|
|
from: 'wagtail/admin/static_src/',
|
|
|
|
|
to: 'wagtail/admin/static/',
|
|
|
|
|
globOptions: { ignore: ['**/{app,scss}/**', '*.{css,txt}'] },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: 'wagtail/documents/static_src/',
|
|
|
|
|
to: 'wagtail/documents/static/',
|
|
|
|
|
globOptions: { ignore: ['**/{app,scss}/**', '*.{css,txt}'] },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: 'wagtail/embeds/static_src/',
|
|
|
|
|
to: 'wagtail/embeds/static/',
|
|
|
|
|
globOptions: { ignore: ['**/{app,scss}/**', '*.{css,txt}'] },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: 'wagtail/images/static_src/',
|
|
|
|
|
to: 'wagtail/images/static/',
|
|
|
|
|
globOptions: { ignore: ['**/{app,scss}/**', '*.{css,txt}'] },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: 'wagtail/search/static_src/',
|
|
|
|
|
to: 'wagtail/search/static/',
|
|
|
|
|
globOptions: { ignore: ['**/{app,scss}/**', '*.{css,txt}'] },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: 'wagtail/users/static_src/',
|
|
|
|
|
to: 'wagtail/users/static/',
|
|
|
|
|
globOptions: { ignore: ['**/{app,scss}/**', '*.{css,txt}'] },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: 'wagtail/contrib/settings/static_src/',
|
|
|
|
|
to: 'wagtail/contrib/settings/static/',
|
|
|
|
|
globOptions: { ignore: ['**/{app,scss}/**', '*.{css,txt}'] },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: 'wagtail/contrib/modeladmin/static_src/',
|
|
|
|
|
to: 'wagtail/contrib/modeladmin/static/',
|
|
|
|
|
globOptions: { ignore: ['**/{app,scss}/**', '*.{css,txt}'] },
|
2022-02-04 12:57:55 +01:00
|
|
|
|
},
|
2021-12-23 05:21:23 +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
|
|
|
|
},
|
2021-12-23 05:21:23 +01:00
|
|
|
|
{
|
|
|
|
|
// Legacy support for font icon loading, to be removed.
|
|
|
|
|
test: /\.(woff)$/i,
|
|
|
|
|
generator: {
|
|
|
|
|
emit: false,
|
|
|
|
|
filename: 'wagtailadmin/fonts/[name][ext]',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.(svg)$/i,
|
|
|
|
|
type: 'asset/inline',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.(scss|css)$/,
|
|
|
|
|
use: [
|
|
|
|
|
MiniCssExtractPlugin.loader,
|
2022-05-11 10:26:20 +02:00
|
|
|
|
{
|
|
|
|
|
loader: 'css-loader',
|
|
|
|
|
options: {
|
|
|
|
|
url: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-12-23 05:21:23 +01:00
|
|
|
|
{
|
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
|
options: {
|
|
|
|
|
postcssOptions: {
|
2022-02-27 17:08:38 +01:00
|
|
|
|
plugins: ['tailwindcss', 'autoprefixer', 'cssnano'],
|
2021-12-23 05:21:23 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'sass-loader',
|
|
|
|
|
],
|
|
|
|
|
},
|
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',
|
2020-12-27 18:53:41 +01:00
|
|
|
|
options: {
|
2020-12-04 12:13:45 +01:00
|
|
|
|
exposes: {
|
|
|
|
|
globalName,
|
|
|
|
|
override: true,
|
2022-02-04 12:57:55 +01:00
|
|
|
|
},
|
2020-12-04 12:13:45 +01:00
|
|
|
|
},
|
2020-12-27 18:53:41 +01:00
|
|
|
|
},
|
2018-01-18 18:06:04 +01:00
|
|
|
|
],
|
|
|
|
|
};
|
2018-01-17 22:23:17 +01:00
|
|
|
|
}),
|
2022-02-04 12:57:55 +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: {
|
2021-12-23 05:21:23 +01:00
|
|
|
|
name: getOutputPath('admin', 'js', 'vendor'),
|
2020-05-29 01:39:20 +02:00
|
|
|
|
chunks: 'initial',
|
|
|
|
|
minChunks: 2,
|
|
|
|
|
reuseExistingChunk: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2018-02-17 13:54:06 +01:00
|
|
|
|
// See https://webpack.js.org/configuration/devtool/.
|
2021-12-23 05:21:23 +01:00
|
|
|
|
devtool: isProduction ? false : 'eval-cheap-module-source-map',
|
2018-02-17 13:54:06 +01:00
|
|
|
|
|
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:21:12 +02:00
|
|
|
|
},
|
2016-02-24 11:44:14 +01:00
|
|
|
|
};
|
|
|
|
|
};
|