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'
const _ = require('lodash')
const path = require('path')
const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin')
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 = {
mode: 'production',
optimization: {
@ -61,9 +83,6 @@ const commonConfig = {
format: process.env.WEBPACK_PROGRESS || 'verbose'
})
],
externals: [
nodeExternals()
],
output: {
path: path.join(__dirname, 'generated'),
filename: '[name].js'
@ -77,6 +96,12 @@ const guiConfig = {
__dirname: true,
__filename: true
},
externals: [
nodeExternals(),
// '../../../package.json' because we are in 'lib/gui/app/index.html'
externalPackageJson('../../../package.json')
],
entry: {
gui: path.join(__dirname, 'lib', 'gui', 'app', 'app.js')
},
@ -90,6 +115,12 @@ const etcherConfig = {
__dirname: false,
__filename: true
},
externals: [
nodeExternals(),
// '../package.json' because we are in 'generated/etcher.js'
externalPackageJson('../package.json')
],
entry: {
etcher: path.join(__dirname, 'lib', 'start.js')
}