From 34f159fc7d9791afcf7e2721f0d45b6c07ca6c0b Mon Sep 17 00:00:00 2001 From: Merkur39 Date: Wed, 7 Dec 2022 17:42:23 +0100 Subject: [PATCH 1/2] chore: Add services scope for bundlemon --- .bundlemonrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.bundlemonrc b/.bundlemonrc index 54902d14..d632cb0f 100644 --- a/.bundlemonrc +++ b/.bundlemonrc @@ -7,6 +7,9 @@ { "path": "app-mespapiers..min.css" }, + { + "path": "services/**/*.js" + }, { "path": "vendors/mespapiers..js" }, From 257493a9ff3dfbbe8ff5a076381b405ce7d1fd00 Mon Sep 17 00:00:00 2001 From: Merkur39 Date: Wed, 7 Dec 2022 17:47:27 +0100 Subject: [PATCH 2/2] chore: Overwrite service webpack configuration The main change is the addition of : ``` optimization: { minimize: false } ``` This temporarily patches the problem with the `mjml` package which does not need to be minified, or at least keep the names of these elements to work --- app.config.js | 5 ++- app.services.js | 105 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 app.services.js diff --git a/app.config.js b/app.config.js index c22457f5..c23d50c2 100644 --- a/app.config.js +++ b/app.config.js @@ -1,5 +1,8 @@ const merge = require('webpack-merge') -const config = [require('cozy-scripts/config/webpack.bundle.default.js')] +const config = [ + require('cozy-scripts/config/webpack.bundle.default.js'), + require('./app.services') +] const extraConfig = { resolve: { diff --git a/app.services.js b/app.services.js new file mode 100644 index 00000000..4e26f929 --- /dev/null +++ b/app.services.js @@ -0,0 +1,105 @@ +const path = require('path') +const fs = require('fs') +const webpack = require('webpack') +const { + target, + eslintFix, + getFilename +} = require('cozy-scripts/config/webpack.vars') +const pathCS = require('cozy-scripts/utils/paths') + +const SRC_DIR = path.resolve(__dirname, 'src') + +const serviceDir = path.resolve(SRC_DIR, './targets/services/') +const servicesPaths = fs.existsSync(serviceDir) + ? fs.readdirSync(serviceDir) + : [] + +const servicesEntries = {} +servicesPaths.forEach(file => { + if (!file.match(/^[^.]*.js$/)) return + const filename = file.match(/^([^.]*).js$/)[1] + servicesEntries[filename] = path.resolve(path.join(serviceDir, file)) +}) + +const config = { + __mergeStrategy: { + smart: false, + strategy: { + plugins: 'replace', + output: 'replace', + entry: 'replace', + optimization: 'replace', + module: 'replace', + externals: 'replace' + } + }, + entry: servicesEntries, + output: { + path: pathCS.appServicesBuild(), + filename: `${getFilename(false)}.js` + }, + target: 'node', + optimization: { + minimize: false + }, + devtool: false, + externals: [], // reset externals property + module: { + rules: [ + { + enforce: 'pre', + test: /\.js$/, + loader: require.resolve('cozy-scripts/node_modules/eslint-loader'), + exclude: /node_modules/, + options: { + extends: ['cozy-app'], + fix: eslintFix, + emitWarning: true + } + }, + { + test: /\.js$/, + exclude: /(node_modules|cozy-(bar|client-js))/, + loader: require.resolve('cozy-scripts/node_modules/babel-loader'), + options: { + cacheDirectory: 'cozy-scripts/node_modules/.cache/babel-loader/node', + babelrc: false, + presets: [['cozy-app', { node: true, react: false }]] + } + } + ], + // Dynamic requires produce warnings in webpack. Some of our dependencies + // use them for features we do not use, so we can disable them. + // More information : https://gitlab.cozycloud.cc/labs/cozy-bank/merge_requests/197#note_4018 + exprContextRegExp: /$^/, + exprContextCritical: false + }, + resolve: { + alias: { + // We are building with target: node as webpack options. This causes webpack + // to consider the "module" entrypoint from node-fetch. This does not work properly + // as require('node-fetch') returns a module object (with the default property). + // Here, we force the resolution to take the commonJS file. + // TODO See if it is necessary to integrate in cozy-scripts + 'node-fetch': 'node-fetch/lib/index.js', + // Unminified Handlebars uses `require.extensions` and this causes + // warnings on Webpack. We should think of a way to precompile + // our Handlebars template. At the moment it is not possible + // since we pass helpers at runtime. + handlebars: 'handlebars/dist/handlebars.min.js' + } + }, + plugins: [ + new webpack.DefinePlugin({ + __TARGET__: JSON.stringify('services') + }) + ] +} + +/* We don't build services if no services and if on mobile build */ +const addServicesConfig = + target === 'browser' && Object.keys(servicesEntries).length + +// only for browser target (services are usable only on cozy-stack) +module.exports = addServicesConfig ? { multiple: { services: config } } : {}