2018-01-12 06:41:02 -05:00
|
|
|
const path = require('path')
|
2021-09-08 05:26:18 -04:00
|
|
|
const glob = require('glob')
|
2019-10-16 06:10:54 -04:00
|
|
|
const webpack = require('webpack')
|
|
|
|
const CopyPlugin = require('copy-webpack-plugin')
|
2021-09-08 04:24:14 -04:00
|
|
|
const WebpackAssetsManifest = require('webpack-assets-manifest')
|
2019-11-28 05:20:22 -05:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
2019-10-16 06:10:54 -04:00
|
|
|
|
|
|
|
const PackageVersions = require('./app/src/infrastructure/PackageVersions')
|
2018-01-12 06:41:02 -05:00
|
|
|
|
2018-03-21 08:08:18 -04:00
|
|
|
// Generate a hash of entry points, including modules
|
2019-10-16 06:10:54 -04:00
|
|
|
const entryPoints = {
|
2021-05-17 05:38:18 -04:00
|
|
|
serviceWorker: './frontend/js/serviceWorker.js',
|
2019-11-05 09:00:13 -05:00
|
|
|
main: './frontend/js/main.js',
|
2019-11-28 05:20:22 -05:00
|
|
|
ide: './frontend/js/ide.js',
|
2021-09-08 05:26:18 -04:00
|
|
|
marketing: './frontend/js/marketing.js',
|
2019-11-28 05:20:22 -05:00
|
|
|
style: './frontend/stylesheets/style.less',
|
|
|
|
'ieee-style': './frontend/stylesheets/ieee-style.less',
|
2021-04-27 03:52:58 -04:00
|
|
|
'light-style': './frontend/stylesheets/light-style.less',
|
2019-10-16 06:10:54 -04:00
|
|
|
}
|
|
|
|
|
2021-09-15 08:10:45 -04:00
|
|
|
// Add entrypoints for each "page"
|
|
|
|
glob
|
|
|
|
.sync(path.join(__dirname, 'modules/*/frontend/js/pages/**/*.js'))
|
|
|
|
.forEach(page => {
|
|
|
|
// in: /workspace/services/web/modules/foo/frontend/js/pages/bar.js
|
|
|
|
// out: modules/foo/pages/bar
|
|
|
|
const name = path
|
|
|
|
.relative(__dirname, page)
|
|
|
|
.replace(/frontend[/]js[/]/, '')
|
|
|
|
.replace(/.js$/, '')
|
|
|
|
entryPoints[name] = './' + path.relative(__dirname, page)
|
|
|
|
})
|
|
|
|
|
2021-09-08 05:26:18 -04:00
|
|
|
glob.sync(path.join(__dirname, 'frontend/js/pages/**/*.js')).forEach(page => {
|
|
|
|
// in: /workspace/services/web/frontend/js/pages/marketing/homepage.js
|
|
|
|
// out: pages/marketing/homepage
|
|
|
|
const name = path
|
|
|
|
.relative(path.join(__dirname, 'frontend/js/'), page)
|
|
|
|
.replace(/.js$/, '')
|
|
|
|
entryPoints[name] = './' + path.relative(__dirname, page)
|
|
|
|
})
|
|
|
|
|
2022-02-07 06:46:51 -05:00
|
|
|
function getModuleDirectory(moduleName) {
|
|
|
|
const entrypointPath = require.resolve(moduleName)
|
|
|
|
const suffix = `node_modules/${moduleName}`
|
|
|
|
const idx = entrypointPath.indexOf(suffix)
|
|
|
|
if (idx === -1) {
|
|
|
|
throw new Error(`could not find Node module: ${moduleName}`)
|
|
|
|
}
|
|
|
|
return entrypointPath.slice(0, idx + suffix.length)
|
|
|
|
}
|
|
|
|
|
|
|
|
const mathjaxDir = getModuleDirectory('mathjax')
|
|
|
|
const aceDir = getModuleDirectory('ace-builds')
|
2022-03-18 06:27:29 -04:00
|
|
|
|
|
|
|
const pdfjsVersions = ['pdfjs-dist210', 'pdfjs-dist213']
|
2022-02-07 06:46:51 -05:00
|
|
|
|
2018-01-12 06:41:02 -05:00
|
|
|
module.exports = {
|
2019-08-06 08:20:02 -04:00
|
|
|
// Defines the "entry point(s)" for the application - i.e. the file which
|
|
|
|
// bootstraps the application
|
|
|
|
entry: entryPoints,
|
2018-01-12 06:41:02 -05:00
|
|
|
|
2019-08-06 08:20:02 -04:00
|
|
|
// Define where and how the bundle will be output to disk
|
|
|
|
// Note: webpack-dev-server does not write the bundle to disk, instead it is
|
|
|
|
// kept in memory for speed
|
|
|
|
output: {
|
2019-11-28 05:20:22 -05:00
|
|
|
path: path.join(__dirname, '/public'),
|
2018-01-12 06:41:02 -05:00
|
|
|
|
2021-09-08 04:24:14 -04:00
|
|
|
publicPath: '/',
|
|
|
|
|
2019-11-28 05:20:22 -05:00
|
|
|
// By default write into js directory
|
|
|
|
filename: 'js/[name].js',
|
2018-01-12 06:41:02 -05:00
|
|
|
|
2019-08-06 08:20:02 -04:00
|
|
|
// Output as UMD bundle (allows main JS to import with CJS, AMD or global
|
|
|
|
// style code bundles
|
|
|
|
libraryTarget: 'umd',
|
|
|
|
// Name the exported variable from output bundle
|
2021-04-27 03:52:58 -04:00
|
|
|
library: ['Frontend', '[name]'],
|
2019-08-06 08:20:02 -04:00
|
|
|
},
|
2018-01-12 06:41:02 -05:00
|
|
|
|
2019-08-06 08:20:02 -04:00
|
|
|
// Define how file types are handled by webpack
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2022-03-15 09:17:43 -04:00
|
|
|
// Pass application JS/TS files through babel-loader, compiling to ES5
|
|
|
|
test: /\.[j|t]sx?$/,
|
2020-06-01 08:16:44 -04:00
|
|
|
// Only compile application files (npm and vendored dependencies are in
|
|
|
|
// ES5 already)
|
|
|
|
exclude: [
|
2021-01-27 04:53:51 -05:00
|
|
|
/node_modules\/(?!react-dnd\/)/,
|
2021-04-27 03:52:58 -04:00
|
|
|
path.resolve(__dirname, 'frontend/js/vendor'),
|
2020-06-01 08:16:44 -04:00
|
|
|
],
|
2019-08-06 08:20:02 -04:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
// Configure babel-loader to cache compiled output so that
|
|
|
|
// subsequent compile runs are much faster
|
2021-04-27 03:52:58 -04:00
|
|
|
cacheDirectory: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2019-08-06 08:20:02 -04:00
|
|
|
},
|
2019-11-28 05:20:22 -05:00
|
|
|
{
|
2022-03-17 07:00:06 -04:00
|
|
|
// Wrap worker scripts in a Web Worker
|
|
|
|
test: /\.worker\.js$/,
|
2019-11-28 05:20:22 -05:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'worker-loader',
|
|
|
|
options: {
|
|
|
|
// Write into js directory (note: customising this is not possible
|
|
|
|
// with pdfjs-dist/webpack auto loader)
|
2022-03-17 07:00:06 -04:00
|
|
|
name: 'js/[name].[contenthash].js',
|
2019-12-11 04:53:31 -05:00
|
|
|
// Override dynamically-set publicPath to explicitly use root.
|
|
|
|
// This prevents a security problem where the Worker - normally
|
|
|
|
// loaded from a CDN - has cross-origin issues, by forcing it to not
|
|
|
|
// be loaded from the CDN
|
2021-04-27 03:52:58 -04:00
|
|
|
publicPath: '/',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2019-11-28 05:20:22 -05:00
|
|
|
},
|
2021-05-17 05:38:18 -04:00
|
|
|
{
|
|
|
|
test: /serviceWorker.js$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'worker-loader',
|
|
|
|
options: {
|
|
|
|
name: 'serviceWorker.js',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-11-28 05:20:22 -05:00
|
|
|
{
|
|
|
|
// Pass Less files through less-loader/css-loader/mini-css-extract-
|
|
|
|
// plugin (note: run in reverse order)
|
|
|
|
test: /\.less$/,
|
|
|
|
use: [
|
|
|
|
// Allows the CSS to be extracted to a separate .css file
|
|
|
|
{ loader: MiniCssExtractPlugin.loader },
|
|
|
|
// Resolves any CSS dependencies (e.g. url())
|
|
|
|
{ loader: 'css-loader' },
|
|
|
|
{
|
|
|
|
// Runs autoprefixer on CSS via postcss
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
// Uniquely identifies the postcss plugin (required by webpack)
|
|
|
|
ident: 'postcss',
|
2021-04-27 03:52:58 -04:00
|
|
|
plugins: [require('autoprefixer')],
|
|
|
|
},
|
2019-11-28 05:20:22 -05:00
|
|
|
},
|
|
|
|
// Compiles the Less syntax to CSS
|
2021-04-27 03:52:58 -04:00
|
|
|
{ loader: 'less-loader' },
|
|
|
|
],
|
2019-11-28 05:20:22 -05:00
|
|
|
},
|
2021-03-18 05:52:36 -04:00
|
|
|
{
|
|
|
|
// Pass CSS files through css-loader & mini-css-extract-plugin (note: run in reverse order)
|
|
|
|
test: /\.css$/i,
|
2021-04-27 03:52:58 -04:00
|
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader'],
|
2021-03-18 05:52:36 -04:00
|
|
|
},
|
2020-01-29 05:25:33 -05:00
|
|
|
{
|
|
|
|
// Load fonts
|
|
|
|
test: /\.(woff|woff2)$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
// Output to public/font
|
|
|
|
outputPath: 'fonts',
|
|
|
|
publicPath: '/fonts/',
|
2021-04-27 03:52:58 -04:00
|
|
|
name: '[name].[ext]',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-01-29 05:25:33 -05:00
|
|
|
},
|
2021-09-30 07:29:25 -04:00
|
|
|
{
|
|
|
|
// Load images (static files)
|
|
|
|
test: /\.(svg|gif|png|jpg|pdf)$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
// Output to public/images
|
|
|
|
outputPath: 'images',
|
|
|
|
publicPath: '/images/',
|
|
|
|
name: '[name].[ext]',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-08-06 08:20:02 -04:00
|
|
|
{
|
2019-10-16 06:10:54 -04:00
|
|
|
// These options are necessary for handlebars to have access to helper
|
2019-08-06 08:20:02 -04:00
|
|
|
// methods
|
|
|
|
test: /\.handlebars$/,
|
|
|
|
loader: 'handlebars-loader',
|
|
|
|
options: {
|
|
|
|
compat: true,
|
|
|
|
knownHelpersOnly: false,
|
2021-04-27 03:52:58 -04:00
|
|
|
runtimePath: 'handlebars/runtime',
|
|
|
|
},
|
2019-10-16 06:10:54 -04:00
|
|
|
},
|
2020-09-03 05:23:34 -04:00
|
|
|
{
|
|
|
|
// Load translations files with custom loader, to extract and apply
|
|
|
|
// fallbacks
|
|
|
|
test: /locales\/(\w{2}(-\w{2})?)\.json$/,
|
|
|
|
use: [
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
loader: path.resolve('frontend/translations-loader.js'),
|
|
|
|
},
|
|
|
|
],
|
2020-09-03 05:23:34 -04:00
|
|
|
},
|
2019-10-16 06:10:54 -04:00
|
|
|
// Allow for injection of modules dependencies by reading contents of
|
|
|
|
// modules directory and adding necessary dependencies
|
|
|
|
{
|
|
|
|
test: path.join(__dirname, 'modules/modules-main.js'),
|
|
|
|
use: [
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
loader: 'val-loader',
|
|
|
|
},
|
|
|
|
],
|
2019-10-16 06:10:54 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: path.join(__dirname, 'modules/modules-ide.js'),
|
|
|
|
use: [
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
loader: 'val-loader',
|
|
|
|
},
|
|
|
|
],
|
2019-10-16 06:10:54 -04:00
|
|
|
},
|
2019-12-16 10:02:29 -05:00
|
|
|
{
|
|
|
|
// Expose jQuery and $ global variables
|
|
|
|
test: require.resolve('jquery'),
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'expose-loader',
|
2021-04-27 03:52:58 -04:00
|
|
|
options: 'jQuery',
|
2019-12-16 10:02:29 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'expose-loader',
|
2021-04-27 03:52:58 -04:00
|
|
|
options: '$',
|
|
|
|
},
|
|
|
|
],
|
2019-12-16 10:02:29 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// Expose angular global variable
|
|
|
|
test: require.resolve('angular'),
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'expose-loader',
|
2021-04-27 03:52:58 -04:00
|
|
|
options: 'angular',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2019-08-06 08:20:02 -04:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
2019-10-16 06:10:54 -04:00
|
|
|
// Aliases for AMD modules
|
|
|
|
|
|
|
|
// Enables ace/ace shortcut
|
2020-11-11 05:50:00 -05:00
|
|
|
ace: 'ace-builds/src-noconflict',
|
2019-10-16 06:10:54 -04:00
|
|
|
// fineupload vendored dependency (which we're aliasing to fineuploadER
|
|
|
|
// for some reason)
|
|
|
|
fineuploader: path.join(
|
|
|
|
__dirname,
|
2019-11-05 09:00:13 -05:00
|
|
|
`frontend/js/vendor/libs/${PackageVersions.lib('fineuploader')}`
|
2021-04-27 03:52:58 -04:00
|
|
|
),
|
|
|
|
},
|
2022-02-07 06:46:51 -05:00
|
|
|
symlinks: false,
|
2022-03-15 09:17:43 -04:00
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
|
2019-10-16 06:10:54 -04:00
|
|
|
},
|
|
|
|
|
2021-09-08 04:24:23 -04:00
|
|
|
// Split out files into separate (derived) bundles if they are shared between
|
|
|
|
// multiple (explicit) bundles, according to some webpack heuristics
|
2019-10-16 06:10:54 -04:00
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
2021-09-08 04:24:23 -04:00
|
|
|
chunks: 'all',
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-10-16 06:10:54 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
// Generate a manifest.json file which is used by the backend to map the
|
|
|
|
// base filenames to the generated output filenames
|
2021-09-08 04:24:14 -04:00
|
|
|
new WebpackAssetsManifest({
|
|
|
|
entrypoints: true,
|
|
|
|
publicPath: true,
|
2019-10-16 06:10:54 -04:00
|
|
|
}),
|
|
|
|
|
2020-01-07 10:23:54 -05:00
|
|
|
// Prevent moment from loading (very large) locale files that aren't used
|
|
|
|
new webpack.IgnorePlugin({
|
|
|
|
resourceRegExp: /^\.\/locale$/,
|
2021-04-27 03:52:58 -04:00
|
|
|
contextRegExp: /moment$/,
|
2020-01-07 10:23:54 -05:00
|
|
|
}),
|
2019-10-16 06:10:54 -04:00
|
|
|
|
2021-03-04 11:10:51 -05:00
|
|
|
// Copy the required files for loading MathJax from MathJax NPM package
|
|
|
|
new CopyPlugin(
|
|
|
|
[
|
|
|
|
{ from: 'MathJax.js', to: 'js/libs/mathjax' },
|
|
|
|
{ from: 'config/**/*', to: 'js/libs/mathjax' },
|
|
|
|
{ from: 'extensions/**/*', to: 'js/libs/mathjax' },
|
|
|
|
{ from: 'localization/en/**/*', to: 'js/libs/mathjax' },
|
|
|
|
{ from: 'jax/output/HTML-CSS/fonts/TeX/**/*', to: 'js/libs/mathjax' },
|
|
|
|
{ from: 'jax/output/HTML-CSS/**/*.js', to: 'js/libs/mathjax' },
|
|
|
|
{ from: 'jax/element/**/*', to: 'js/libs/mathjax' },
|
|
|
|
{ from: 'jax/input/**/*', to: 'js/libs/mathjax' },
|
2021-04-27 03:52:58 -04:00
|
|
|
{ from: 'fonts/HTML-CSS/TeX/woff/*', to: 'js/libs/mathjax' },
|
2021-03-04 11:10:51 -05:00
|
|
|
],
|
2019-10-30 07:19:44 -04:00
|
|
|
{
|
2022-02-07 06:46:51 -05:00
|
|
|
context: mathjaxDir,
|
2021-03-04 11:10:51 -05:00
|
|
|
}
|
|
|
|
),
|
|
|
|
|
|
|
|
new CopyPlugin([
|
2019-10-30 07:19:44 -04:00
|
|
|
{
|
2019-11-05 09:00:13 -05:00
|
|
|
from: 'frontend/js/vendor/libs/sigma-master',
|
2021-04-27 03:52:58 -04:00
|
|
|
to: 'js/libs/sigma-master',
|
2019-10-30 07:19:44 -04:00
|
|
|
},
|
|
|
|
{
|
2022-02-07 06:46:51 -05:00
|
|
|
from: `${aceDir}/src-min-noconflict`,
|
2021-04-27 03:52:58 -04:00
|
|
|
to: `js/ace-${PackageVersions.version.ace}/`,
|
2019-10-30 07:19:44 -04:00
|
|
|
},
|
2022-03-18 06:27:29 -04:00
|
|
|
...pdfjsVersions.flatMap(version => {
|
|
|
|
const dir = getModuleDirectory(version)
|
|
|
|
|
|
|
|
// Copy CMap files (used to provide support for non-Latin characters)
|
|
|
|
// and static images from pdfjs-dist package to build output.
|
|
|
|
|
|
|
|
return [
|
2022-03-18 09:23:34 -04:00
|
|
|
{ from: `${dir}/cmaps`, to: `js/${version}/cmaps` },
|
2022-03-18 06:27:29 -04:00
|
|
|
{
|
|
|
|
from: `${dir}/legacy/web/images`,
|
2022-03-18 09:23:34 -04:00
|
|
|
to: `images/${version}`,
|
2022-03-18 06:27:29 -04:00
|
|
|
},
|
|
|
|
]
|
|
|
|
}),
|
2021-04-27 03:52:58 -04:00
|
|
|
]),
|
|
|
|
],
|
2018-03-29 11:15:53 -04:00
|
|
|
}
|