diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 09:07:48 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 09:07:48 +0000 |
commit | 5bd24a54ef4ce3a38a860eb53b66d062c2382971 (patch) | |
tree | 5f5e65571dfcb2c62c27600ee7655dec4b44c923 /config | |
parent | 74673d04d25ffed35cbcf17cd42969bed0a4e705 (diff) | |
download | gitlab-ce-5bd24a54ef4ce3a38a860eb53b66d062c2382971.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'config')
-rw-r--r-- | config/helpers/vendor_dll_hash.js | 23 | ||||
-rw-r--r-- | config/webpack.config.js | 43 | ||||
-rw-r--r-- | config/webpack.vendor.config.js | 71 |
3 files changed, 136 insertions, 1 deletions
diff --git a/config/helpers/vendor_dll_hash.js b/config/helpers/vendor_dll_hash.js new file mode 100644 index 00000000000..cfd7be66ad3 --- /dev/null +++ b/config/helpers/vendor_dll_hash.js @@ -0,0 +1,23 @@ +const fs = require('fs'); +const path = require('path'); +const crypto = require('crypto'); + +const CACHE_PATHS = [ + './config/webpack.config.js', + './config/webpack.vendor.config.js', + './package.json', + './yarn.lock', +]; + +const resolvePath = file => path.resolve(__dirname, '../..', file); +const readFile = file => fs.readFileSync(file); +const fileHash = buffer => + crypto + .createHash('md5') + .update(buffer) + .digest('hex'); + +module.exports = () => { + const fileBuffers = CACHE_PATHS.map(resolvePath).map(readFile); + return fileHash(Buffer.concat(fileBuffers)).substr(0, 12); +}; diff --git a/config/webpack.config.js b/config/webpack.config.js index c0be2f66ca7..d85fa84c32f 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -1,6 +1,6 @@ +const fs = require('fs'); const path = require('path'); const glob = require('glob'); -const fs = require('fs'); const webpack = require('webpack'); const VueLoaderPlugin = require('vue-loader/lib/plugin'); const StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin; @@ -8,8 +8,10 @@ const CompressionPlugin = require('compression-webpack-plugin'); const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; const CopyWebpackPlugin = require('copy-webpack-plugin'); +const vendorDllHash = require('./helpers/vendor_dll_hash'); 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'; @@ -113,6 +115,25 @@ if (IS_EE) { }); } +// if there is a compiled DLL with a matching hash string, use it +let dll; + +if (VENDOR_DLL && !IS_PRODUCTION) { + const dllHash = vendorDllHash(); + const dllCachePath = path.join(ROOT_PATH, `tmp/cache/webpack-dlls/${dllHash}`); + if (fs.existsSync(dllCachePath)) { + console.log(`Using vendor DLL found at: ${dllCachePath}`); + dll = { + manifestPath: path.join(dllCachePath, 'vendor.dll.manifest.json'), + cacheFrom: dllCachePath, + cacheTo: path.join(ROOT_PATH, `public/assets/webpack/dll.${dllHash}/`), + publicPath: `dll.${dllHash}/vendor.dll.bundle.js`, + }; + } else { + console.log(`Warning: No vendor DLL found at: ${dllCachePath}. DllPlugin disabled.`); + } +} + module.exports = { mode: IS_PRODUCTION ? 'production' : 'development', @@ -267,6 +288,11 @@ module.exports = { modules: false, assets: true, }); + + // tell our rails helper where to find the DLL files + if (dll) { + stats.dllAssets = dll.publicPath; + } return JSON.stringify(stats, null, 2); }, }), @@ -286,6 +312,21 @@ module.exports = { jQuery: 'jquery', }), + // reference our compiled DLL modules + dll && + new webpack.DllReferencePlugin({ + context: ROOT_PATH, + manifest: dll.manifestPath, + }), + + dll && + new CopyWebpackPlugin([ + { + from: dll.cacheFrom, + to: dll.cacheTo, + }, + ]), + !IS_EE && new webpack.NormalModuleReplacementPlugin(/^ee_component\/(.*)\.vue/, resource => { resource.request = path.join( diff --git a/config/webpack.vendor.config.js b/config/webpack.vendor.config.js new file mode 100644 index 00000000000..bddbf067d7c --- /dev/null +++ b/config/webpack.vendor.config.js @@ -0,0 +1,71 @@ +const path = require('path'); +const webpack = require('webpack'); +const vendorDllHash = require('./helpers/vendor_dll_hash'); + +const ROOT_PATH = path.resolve(__dirname, '..'); + +const dllHash = vendorDllHash(); +const dllCachePath = path.join(ROOT_PATH, `tmp/cache/webpack-dlls/${dllHash}`); +const dllPublicPath = `/assets/webpack/dll.${dllHash}/`; + +module.exports = { + mode: 'development', + resolve: { + extensions: ['.js'], + }, + + context: ROOT_PATH, + + entry: { + vendor: [ + 'jquery', + 'pdfjs-dist/build/pdf', + 'pdfjs-dist/build/pdf.worker.min', + 'sql.js', + 'core-js', + 'echarts', + 'lodash', + 'underscore', + 'vuex', + 'pikaday', + 'vue/dist/vue.esm.js', + 'at.js', + 'jed', + 'mermaid', + 'katex', + 'three', + 'select2', + 'moment', + 'aws-sdk', + 'sanitize-html', + 'bootstrap/dist/js/bootstrap.js', + 'sortablejs/modular/sortable.esm.js', + 'popper.js', + 'apollo-client', + 'source-map', + 'mousetrap', + ], + }, + + output: { + path: dllCachePath, + publicPath: dllPublicPath, + filename: '[name].dll.bundle.js', + chunkFilename: '[name].dll.chunk.js', + library: '[name]_[hash]', + }, + + plugins: [ + new webpack.DllPlugin({ + path: path.join(dllCachePath, '[name].dll.manifest.json'), + name: '[name]_[hash]', + }), + ], + + node: { + fs: 'empty', // sqljs requires fs + setImmediate: false, + }, + + devtool: 'cheap-module-source-map', +}; |