-
-
Notifications
You must be signed in to change notification settings - Fork 202
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
feat(custom-esbuild): add support for plugin configuration #1683
feat(custom-esbuild): add support for plugin configuration #1683
Conversation
81890a5
to
aa53635
Compare
examples/custom-esbuild/sanity-esbuild-app-esm/esbuild/define-text-by-option-plugin.cjs
Show resolved
Hide resolved
Can you give me a hint, how I can actually run the examples without copying things around? |
@spike-rabbit Once you run Did I answer your question or you meant something else? |
8516e5d
to
239abb4
Compare
Thx, I solved my problem. I should have run |
239abb4
to
6359159
Compare
examples/custom-esbuild/sanity-esbuild-app-esm/esbuild/define-text-by-option-plugin.cjs
Show resolved
Hide resolved
name: 'define-title', | ||
setup(build) { | ||
const options = build.initialOptions; | ||
options.define.titleByOption = JSON.stringify(pluginOptions.title); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here (remove JSON.stringify
)
examples/custom-esbuild/sanity-esbuild-app-esm/esbuild/define-text-by-option-plugin.ts
Show resolved
Hide resolved
examples/custom-esbuild/sanity-esbuild-app/esbuild/define-text-by-option-plugin.js
Show resolved
Hide resolved
examples/custom-esbuild/sanity-esbuild-app/esbuild/define-text-by-option-plugin.mjs
Show resolved
Hide resolved
packages/custom-esbuild/README.md
Outdated
@@ -112,7 +112,7 @@ Builder options: | |||
|
|||
In the above example, we specify the list of `plugins` that should implement the ESBuild plugin schema. These plugins are custom user plugins and are added to the original ESBuild Angular configuration. Additionally, the `indexHtmlTransformer` property is used to specify the path to the file that exports the function used to modify the `index.html`. | |||
|
|||
The plugin file can export either a single plugin or a list of plugins: | |||
The plugin file can export either a single plugin, a single plugin with configuration or a list of plugins: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rephrase to:
The plugin file can export either a single plugin or a list of plugins. If a plugin accepts configuration then the config should be provided in `angular.json`:
6359159
to
cefcaf9
Compare
@just-jeb I changed everything as requested. Can you release the changes once this is merged? |
packages/custom-esbuild/README.md
Outdated
@@ -100,7 +100,7 @@ Builder options: | |||
"build": { | |||
"builder": "@angular-builders/custom-esbuild:application", | |||
"options": { | |||
"plugins": ["./esbuild/plugins.ts", "./esbuild/plugin-2.js"], | |||
"plugins": ["./esbuild/plugins.ts", { "path": "./esbuild/plugin-2.js", "options": { "key": "value" } }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we please have a more practical example demonstrating its usefulness? For instance, could you provide an example involving a real plugin that necessitates options, or perhaps share a scenario from your own application illustrating why it's essential?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense for me, but I found a bug which makes using 3rd party plugins (almost) impossible.
Paths are always joined with the workspaceRoot loadModule<Plugin | Plugin[]>(path.join(workspaceRoot, pluginPath), tsConfig, logger)
. This makes it impossible to load modules by the package name.
I would propose to remove this and just use the plugin path without the workspace root. Unless I missed something, this would be inline with the behavior of custom-webpack.
If you agree, I can do this in another MR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we merge it and have a separate PR for 3rd party plugins (and then update the example)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spike-rabbit Hmmm I wonder if that's the reason for JSON.stringify
(CI fails now):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- JSON stringify is back
- updated the README
cefcaf9
to
6819f24
Compare
packages/custom-esbuild/README.md
Outdated
// esbuild/plugins.ts | ||
import type { Plugin, PluginBuild } from 'esbuild'; | ||
|
||
function defineRewritePathPlugin(options: { text: string }): Plugin { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the esbuild/define-env.ts
example, along with a practical illustration of how the stage
parameter could be utilized. Please avoid providing text examples, as they are unnecessary.
The define.buildText
only shows how to define the global compile-time constant, but the current showcase should illustrate how options are useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is updated
6819f24
to
81f145d
Compare
@arturovt is it all good from your perspective? Can we merge? |
Is there any update on this? As a consumer I would LOVE to be able to pass in configuration via the angular.json |
Would indeed be nice having this merged. I am still available to do changes if needed |
@spike-rabbit can you rebase on master? |
81f145d
to
fca7cfb
Compare
rebase done |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
esbuild plugin options cannot be provided
Issue Number: #1661
What is the new behavior?
esbuild plugin options can be provided using
Does this PR introduce a breaking change?
Other information