Don't webpack package.json as analytics tokens are interted after webpacking

Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-01-14 14:23:21 +01:00 committed by Lorenzo Alberto Maria Ambrosi
parent 171a5b1793
commit 12b5536e22

View File

@ -16,10 +16,32 @@
'use strict' 'use strict'
const _ = require('lodash')
const path = require('path') const path = require('path')
const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin') const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin')
const nodeExternals = require('webpack-node-externals') const nodeExternals = require('webpack-node-externals')
/**
* Don't webpack package.json as mixpanel & sentry tokens
* will be inserted in it after webpacking
*
* @param {*} packageJsonPath - Path for the package.json file
* @returns {void}
*
* @example webpack externals:
* [
* externalPackageJson('./package.json')
* ]
*/
const externalPackageJson = (packageJsonPath) => {
return (_context, request, callback) => {
if (_.endsWith(request, 'package.json')) {
return callback(null, `commonjs ${packageJsonPath}`)
}
return callback()
}
}
const commonConfig = { const commonConfig = {
mode: 'production', mode: 'production',
optimization: { optimization: {
@ -61,9 +83,6 @@ const commonConfig = {
format: process.env.WEBPACK_PROGRESS || 'verbose' format: process.env.WEBPACK_PROGRESS || 'verbose'
}) })
], ],
externals: [
nodeExternals()
],
output: { output: {
path: path.join(__dirname, 'generated'), path: path.join(__dirname, 'generated'),
filename: '[name].js' filename: '[name].js'
@ -77,6 +96,12 @@ const guiConfig = {
__dirname: true, __dirname: true,
__filename: true __filename: true
}, },
externals: [
nodeExternals(),
// '../../../package.json' because we are in 'lib/gui/app/index.html'
externalPackageJson('../../../package.json')
],
entry: { entry: {
gui: path.join(__dirname, 'lib', 'gui', 'app', 'app.js') gui: path.join(__dirname, 'lib', 'gui', 'app', 'app.js')
}, },
@ -90,6 +115,12 @@ const etcherConfig = {
__dirname: false, __dirname: false,
__filename: true __filename: true
}, },
externals: [
nodeExternals(),
// '../package.json' because we are in 'generated/etcher.js'
externalPackageJson('../package.json')
],
entry: { entry: {
etcher: path.join(__dirname, 'lib', 'start.js') etcher: path.join(__dirname, 'lib', 'start.js')
} }