Skip to content

Commit

Permalink
Merge pull request #255 from rdkcentral/feature/custom-esbuild
Browse files Browse the repository at this point in the history
Feature/custom esbuild
  • Loading branch information
michielvandergeest authored Apr 3, 2024
2 parents 68f9d90 + 8c2435b commit dddb603
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
],
"eslint.alwaysShowStatus": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
3 changes: 2 additions & 1 deletion docs/environmentvariables.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ You can use the following environment variables to customize the behavior of the
| `LNG_BUNDLER_ESBUILD_OPTIONS` | false | Specifies the specific bundler options required for esbuild
| `LNG_BUNDLER_ROLLUP_OPTIONS` | false | Specifies the specific bundler options required for rollup
| `LNG_BUILD_MINIFY` | false | When set to `true` minifies the bundle
| `LNG_CUSTOM_ROLLUP` | false | When set to `true`, uses the custom rollup config file located in the project home directory
| `LNG_CUSTOM_ROLLUP` | false | When set to `true`, uses the custom rollup config file(rollup.{env}.config.js) located in the project home directory
| `LNG_CUSTOM_ESBUILD` | false | When set to `true`, uses the custom esbuild config file located(esbuild.{env}.config.js) in the project home directory

#### `LNG_SETTINGS_ENV`
Specifies which environment to be used. User need to have `settings.{env}.json` file in the Project home folder with different settings. This will build/dist the application with `settings.{env}.json`.
Expand Down
14 changes: 13 additions & 1 deletion src/configs/esbuild.es5.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ const babelPluginTransFormSpread = require('@babel/plugin-transform-spread')
const babelPluginTransFormParameters = require('@babel/plugin-transform-parameters')
const babelPluginClassProperties = require('@babel/plugin-proposal-class-properties')
const babelPluginInlineJsonImport = require('babel-plugin-inline-json-import')
const deepMerge = require('deepmerge')

let customConfig

if (process.env.LNG_CUSTOM_ESBUILD === 'true') {
customConfig = require(path.join(process.cwd(), 'esbuild.es5.config'))
}

module.exports = (folder, globalName) => {
// Load .env config every time build is triggered
Expand All @@ -43,7 +50,7 @@ module.exports = (folder, globalName) => {
defined['process.env.NODE_ENV'] = `"${process.env.NODE_ENV}"`
const minify = process.env.LNG_BUILD_MINIFY === 'true' || process.env.NODE_ENV === 'production'

return {
let defaultConfig = {
plugins: [
alias([
{ find: '@', filter: /@\//, replace: path.resolve(process.cwd(), 'src/') },
Expand Down Expand Up @@ -117,4 +124,9 @@ module.exports = (folder, globalName) => {
].join(os.EOL),
},
}
if ('entryPoints' in customConfig) {
delete defaultConfig.entryPoints
}
const finalConfig = customConfig ? deepMerge(defaultConfig, customConfig) : defaultConfig
return finalConfig
}
16 changes: 14 additions & 2 deletions src/configs/esbuild.es6.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ const babelPresetEnv = require('@babel/preset-env')
const path = require('path')
const babelPluginClassProperties = require('@babel/plugin-proposal-class-properties')
const babelPluginInlineJsonImport = require('babel-plugin-inline-json-import')
const deepMerge = require('deepmerge')

let customConfig

if (process.env.LNG_CUSTOM_ESBUILD === 'true') {
customConfig = require(path.join(process.cwd(), 'esbuild.es6.config'))
}

module.exports = (folder, globalName) => {
//Load .env config every time build is triggered
Expand All @@ -40,8 +47,7 @@ module.exports = (folder, globalName) => {
}, {})
defined['process.env.NODE_ENV'] = `"${process.env.NODE_ENV}"`
const minify = process.env.LNG_BUILD_MINIFY === 'true' || process.env.NODE_ENV === 'production'

return {
let defaultConfig = {
plugins: [
alias([
{
Expand Down Expand Up @@ -107,4 +113,10 @@ module.exports = (folder, globalName) => {
].join(os.EOL),
},
}

if ('entryPoints' in customConfig) {
delete defaultConfig.entryPoints
}
const finalConfig = customConfig ? deepMerge(defaultConfig, customConfig) : defaultConfig
return finalConfig
}

0 comments on commit dddb603

Please sign in to comment.