diff options
Diffstat (limited to 'config/webpack.config.js')
-rw-r--r-- | config/webpack.config.js | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/config/webpack.config.js b/config/webpack.config.js index 19059c35c46..39add7def22 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -1,25 +1,34 @@ const fs = require('fs'); -const path = require('path'); -const glob = require('glob'); -const webpack = require('webpack'); -const VueLoaderPlugin = require('vue-loader/lib/plugin'); -const StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin; + +const SOURCEGRAPH_VERSION = require('@sourcegraph/code-host-integration/package.json').version; + const CompressionPlugin = require('compression-webpack-plugin'); -const MonacoWebpackPlugin = require('./plugins/monaco_webpack'); -const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; const CopyWebpackPlugin = require('copy-webpack-plugin'); -const vendorDllHash = require('./helpers/vendor_dll_hash'); +const glob = require('glob'); +const path = require('path'); +const VueLoaderPlugin = require('vue-loader/lib/plugin'); +const VUE_LOADER_VERSION = require('vue-loader/package.json').version; +const VUE_VERSION = require('vue/package.json').version; +const webpack = require('webpack'); +const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); +const { StatsWriterPlugin } = require('webpack-stats-plugin'); +const WEBPACK_VERSION = require('webpack/package.json').version; + const createIncrementalWebpackCompiler = require('./helpers/incremental_webpack_compiler'); +const IS_EE = require('./helpers/is_ee_env'); +const vendorDllHash = require('./helpers/vendor_dll_hash'); + +const MonacoWebpackPlugin = require('./plugins/monaco_webpack'); const ROOT_PATH = path.resolve(__dirname, '..'); const VENDOR_DLL = process.env.WEBPACK_VENDOR_DLL && process.env.WEBPACK_VENDOR_DLL !== 'false'; const CACHE_PATH = process.env.WEBPACK_CACHE_PATH || path.join(ROOT_PATH, 'tmp/cache'); const IS_PRODUCTION = process.env.NODE_ENV === 'production'; const IS_DEV_SERVER = process.env.WEBPACK_DEV_SERVER === 'true'; -const IS_EE = require('./helpers/is_ee_env'); + const DEV_SERVER_HOST = process.env.DEV_SERVER_HOST || 'localhost'; const DEV_SERVER_PORT = parseInt(process.env.DEV_SERVER_PORT, 10) || 3808; -const DEV_SERVER_PUBLIC_ADDR = process.env.DEV_SERVER_PUBLIC_ADDR; +const { DEV_SERVER_PUBLIC_ADDR } = process.env; const DEV_SERVER_ALLOWED_HOSTS = process.env.DEV_SERVER_ALLOWED_HOSTS && process.env.DEV_SERVER_ALLOWED_HOSTS.split(','); const DEV_SERVER_HTTPS = process.env.DEV_SERVER_HTTPS && process.env.DEV_SERVER_HTTPS !== 'false'; @@ -38,11 +47,6 @@ const WEBPACK_OUTPUT_PATH = path.join(ROOT_PATH, 'public/assets/webpack'); const WEBPACK_PUBLIC_PATH = '/assets/webpack/'; const SOURCEGRAPH_PACKAGE = '@sourcegraph/code-host-integration'; -const VUE_VERSION = require('vue/package.json').version; -const VUE_LOADER_VERSION = require('vue-loader/package.json').version; -const WEBPACK_VERSION = require('webpack/package.json').version; -const SOURCEGRAPH_VERSION = require(path.join(SOURCEGRAPH_PACKAGE, 'package.json')).version; - const SOURCEGRAPH_PATH = path.join('sourcegraph', SOURCEGRAPH_VERSION, '/'); const SOURCEGRAPH_OUTPUT_PATH = path.join(WEBPACK_OUTPUT_PATH, SOURCEGRAPH_PATH); const SOURCEGRAPH_PUBLIC_PATH = path.join(WEBPACK_PUBLIC_PATH, SOURCEGRAPH_PATH); @@ -67,19 +71,19 @@ function generateEntries() { }); watchAutoEntries = [path.join(ROOT_PATH, 'app/assets/javascripts/pages/')]; - function generateAutoEntries(path, prefix = '.') { - const chunkPath = path.replace(/\/index\.js$/, ''); + function generateAutoEntries(entryPath, prefix = '.') { + const chunkPath = entryPath.replace(/\/index\.js$/, ''); const chunkName = chunkPath.replace(/\//g, '.'); - autoEntriesMap[chunkName] = `${prefix}/${path}`; + autoEntriesMap[chunkName] = `${prefix}/${entryPath}`; } - pageEntries.forEach((path) => generateAutoEntries(path)); + pageEntries.forEach((entryPath) => generateAutoEntries(entryPath)); if (IS_EE) { const eePageEntries = glob.sync('pages/**/index.js', { cwd: path.join(ROOT_PATH, 'ee/app/assets/javascripts'), }); - eePageEntries.forEach((path) => generateAutoEntries(path, 'ee')); + eePageEntries.forEach((entryPath) => generateAutoEntries(entryPath, 'ee')); watchAutoEntries.push(path.join(ROOT_PATH, 'ee/app/assets/javascripts/pages/')); } @@ -101,9 +105,8 @@ function generateEntries() { const manualEntries = { default: defaultEntries, - // sentry: './sentry/index.js', Temporarily commented out to investigate performance: https://gitlab.com/gitlab-org/gitlab/-/issues/251179 + sentry: './sentry/index.js', performance_bar: './performance_bar/index.js', - chrome_84_icon_fix: './lib/chrome_84_icon_fix.js', jira_connect_app: './jira_connect/index.js', }; @@ -198,9 +201,9 @@ module.exports = { }, { test: /\.js$/, - exclude: (path) => - /node_modules\/(?!tributejs)|node_modules|vendor[\\/]assets/.test(path) && - !/\.vue\.js/.test(path), + exclude: (modulePath) => + /node_modules\/(?!tributejs)|node_modules|vendor[\\/]assets/.test(modulePath) && + !/\.vue\.js/.test(modulePath), loader: 'babel-loader', options: { cacheDirectory: path.join(CACHE_PATH, 'babel-loader'), @@ -354,7 +357,7 @@ module.exports = { // webpack-rails only needs assetsByChunkName to function properly new StatsWriterPlugin({ filename: 'manifest.json', - transform: function (data, opts) { + transform(data, opts) { const stats = opts.compiler.getStats().toJson({ chunkModules: false, source: false, @@ -412,6 +415,7 @@ module.exports = { `Warning: No vendor DLL found at: ${dll.cacheFrom}. Compiling DLL automatically.`, ); + // eslint-disable-next-line global-require const dllConfig = require('./webpack.vendor.config.js'); const dllCompiler = webpack(dllConfig); @@ -435,7 +439,7 @@ module.exports = { } dll.exists = true; - callback(); + return callback(); }); } }); @@ -459,6 +463,7 @@ module.exports = { !IS_EE && new webpack.NormalModuleReplacementPlugin(/^ee_component\/(.*)\.vue/, (resource) => { + // eslint-disable-next-line no-param-reassign resource.request = path.join( ROOT_PATH, 'app/assets/javascripts/vue_shared/components/empty_component.js', @@ -521,7 +526,7 @@ module.exports = { // output the in-memory heap size upon compilation and exit WEBPACK_MEMORY_TEST && { apply(compiler) { - compiler.hooks.emit.tapAsync('ReportMemoryConsumptionPlugin', (compilation, callback) => { + compiler.hooks.emit.tapAsync('ReportMemoryConsumptionPlugin', () => { console.log('Assets compiled...'); if (global.gc) { console.log('Running garbage collection...'); @@ -552,7 +557,9 @@ module.exports = { ); // exit in case we're running webpack-dev-server - IS_DEV_SERVER && process.exit(); + if (IS_DEV_SERVER) { + process.exit(); + } }); }, }, |