Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/custom esbuild #255

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the env?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ricardo-a-alves-alb ,
The ones that are mentioned in the env will be ignored here and the custom config takes the priority here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've misread the configuration description. By env, I thought it meant like development, staging and production. But now I see that it's about es5 and es6.

}

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
}