diff --git a/services/web/app/src/infrastructure/ExpressLocals.js b/services/web/app/src/infrastructure/ExpressLocals.js index 2d26ac2b24..d6d4ddf4d1 100644 --- a/services/web/app/src/infrastructure/ExpressLocals.js +++ b/services/web/app/src/infrastructure/ExpressLocals.js @@ -19,15 +19,13 @@ const Modules = require('./Modules') const htmlEncoder = new NodeHtmlEncoder('numerical') -const jsPath = Settings.useMinifiedJs ? '/minjs/' : '/js/' - let webpackManifest if (!IS_DEV_ENV) { // Only load webpack manifest file in production. In dev, the web and webpack // containers can't coordinate, so there no guarantee that the manifest file // exists when the web server boots. We therefore ignore the manifest file in // dev reload - webpackManifest = require(`../../../public${jsPath}manifest.json`) + webpackManifest = require(`../../../public/js/manifest.json`) } function getFileContent(filePath) { @@ -133,7 +131,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) { // In dev: resolve path within JS asset directory // We are *not* guaranteed to have a manifest file when the server // starts up - path = Path.join(jsPath, jsFile) + path = Path.join('/js', jsFile) } else { // In production: resolve path from webpack manifest file // We are guaranteed to have a manifest file since webpack compiles in @@ -152,10 +150,6 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) { return path } - res.locals.buildAssetsPath = function(path) { - return `${jsPath}/${path}` - } - res.locals.mathJaxPath = res.locals.buildJsPath('libs/mathjax/MathJax.js', { cdn: false, qs: { config: 'TeX-AMS_HTML,Safe' } diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index fcd42af0ed..0cf754ffa7 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -137,9 +137,9 @@ block content window.wikiEnabled = #{!!(settings.apis.wiki && settings.apis.wiki.url)}; window.gitBridgePublicBaseUrl = '#{gitBridgePublicBaseUrl}' //- Set base path for Ace scripts loaded on demand/workers and don't use cdn - window.aceBasePath = "#{buildAssetsPath(lib('ace'))}" + window.aceBasePath = "/js/#{lib('ace')}" //- Set path for PDFjs CMaps - window.pdfCMapsPath = "#{buildAssetsPath('cmaps/')}" + window.pdfCMapsPath = "/js/cmaps/" window.uiConfig = JSON.parse('!{StringHelper.stringifyJsonForScript(uiConfig)}'); //- enable doc hash checking for all projects //- used in public/js/libs/sharejs.js diff --git a/services/web/package.json b/services/web/package.json index ba3579ab6e..47aa34a11e 100644 --- a/services/web/package.json +++ b/services/web/package.json @@ -23,7 +23,7 @@ "nodemon": "nodemon --config nodemon.json", "nodemon:frontend": "nodemon --config nodemon.frontend.json", "webpack": "webpack-dev-server --config webpack.config.dev.js", - "webpack:production": "webpack --config webpack.config.prod.js", + "webpack:production": "webpack --config webpack.config.prod.js && cp -R public/js public/minjs", "lint": "eslint -f unix .", "format": "prettier-eslint '**/*.js' --list-different", "format:fix": "prettier-eslint '**/*.js' --write", diff --git a/services/web/webpack.config.dev.js b/services/web/webpack.config.dev.js index 2623942457..13a895c335 100644 --- a/services/web/webpack.config.dev.js +++ b/services/web/webpack.config.dev.js @@ -8,10 +8,6 @@ module.exports = merge(base, { // Enable source maps for dev (fast compilation, slow runtime) devtool: 'cheap-module-eval-source-map', - output: { - publicPath: '/js/' - }, - devServer: { // Disable webpack dev server auto-reload inline: false, diff --git a/services/web/webpack.config.js b/services/web/webpack.config.js index 3e109e4f99..bcf802167e 100644 --- a/services/web/webpack.config.js +++ b/services/web/webpack.config.js @@ -14,9 +14,9 @@ const entryPoints = { ide: './frontend/js/ide.js' } +// Attempt to load frontend entry-points from modules, if they exist if (fs.existsSync(MODULES_PATH)) { fs.readdirSync(MODULES_PATH).reduce((acc, module) => { - // FIXME: modules frontend path const entryPath = path.join(MODULES_PATH, module, '/frontend/js/index.js') if (fs.existsSync(entryPath)) { acc[module] = entryPath @@ -36,6 +36,9 @@ module.exports = { output: { path: path.join(__dirname, '/public/js'), + // Serve from /js + publicPath: '/js/', + filename: '[name].js', // Output as UMD bundle (allows main JS to import with CJS, AMD or global diff --git a/services/web/webpack.config.prod.js b/services/web/webpack.config.prod.js index bf7a03e1d8..99e41143f4 100644 --- a/services/web/webpack.config.prod.js +++ b/services/web/webpack.config.prod.js @@ -1,4 +1,3 @@ -const path = require('path') const merge = require('webpack-merge') const base = require('./webpack.config') @@ -10,12 +9,7 @@ module.exports = merge(base, { devtool: 'source-map', output: { - // Override output path to minjs dir - path: path.join(__dirname, '/public/minjs'), - // Override filename to include hash for immutable caching - filename: '[name]-[chunkhash].js', - - publicPath: '/minjs/' + filename: '[name]-[chunkhash].js' } })