-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#9 add watch mode with hmr
- Loading branch information
Showing
61 changed files
with
4,850 additions
and
4,127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
**/dist | ||
**/build | ||
.pnpm-debug.log | ||
**/.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,90 @@ | ||
# liferay-npm-bundler-improved | ||
|
||
A non-official but **ultrafast** drop-in replacement for the | ||
[`liferay-npm-bundler` \*](https://www.npmjs.com/package/liferay-npm-bundler) | ||
`liferay-npm-bundler-improved` is a **high-speed**, unofficial drop-in replacement for | ||
the [`liferay-npm-bundler`](https://www.npmjs.com/package/liferay-npm-bundler) with added watch mode functionality. | ||
|
||
## advantages | ||
## description | ||
|
||
the two main advantages are _**speed**_ and _**traceability**_. | ||
`liferay-npm-bundler-improved` is a bundler for liferay portlets that consolidates all dependencies into a single file. | ||
Additionally, it copies assets into the `build` folder and provides access to them through the web context URL. The tool | ||
also offers a watch mode that rebuilds the portlet upon file changes. | ||
|
||
### speed | ||
## getting started | ||
|
||
a build of an average portlet with the `liferay-npm-bundler-improved` takes about **_0.1s_** \*\*, no matter how big the | ||
module is. if you worked with the official `liferay-npm-bundler` before, you know how much of an improvement this is. | ||
### installation | ||
|
||
### traceability | ||
To install, run the following command: | ||
|
||
the `liferay-npm-bundler-improved` tries its best to tell you, if you do something wrong. this helps the developer a | ||
lot if he is trying to figure out why something isn't working as expected. some examples. | ||
```bash | ||
pnpm i --D liferay-npm-bundler-improved | ||
``` | ||
|
||
#### missing key in `package.json` | ||
### existing portlet | ||
|
||
if you forgot a required key in the `package.json`, it tells you which key you're missing and lets the build fail. | ||
for example, if you forgot the `name` key, the console output would look something like this: | ||
To use `liferay-npm-bundler-improved` in an existing portlet, replace instances of `liferay-npm-bundler` | ||
with `liferay-npm-bundler-improved` in your build command. | ||
|
||
``` | ||
Error in 0.01s: bundler failed. invalid-package-exception: required property "name" doesn't exist in the package.json file. | ||
``` | ||
#### copy sources | ||
|
||
#### missing entry file | ||
If your build command includes `lnbs-copy-sources`, remove it and add `--copy-sources` to | ||
the `liferay-npm-bundler-improved` command. | ||
|
||
if, for some reason, the in the `main` property defined entry js file is missing, the bundler will show the following | ||
output. _(the original bundler wouldn't even fail if the entry file was not found. it would just tell you that its | ||
finished.)_ | ||
#### copy assets | ||
|
||
with the `--copy-sources` option activated: | ||
For assets located in the `assets` folder that need to be available through the web context URL, remove | ||
the `lnbs-copy-assets` command from your existing build command and add `--copy-assets` to | ||
the `liferay-npm-bundler-improved` call. | ||
|
||
``` | ||
Error in 0.01s: bundler failed. copy-sources-exception: sources could not be copied from "src/entry.js" | ||
``` | ||
### new portlet | ||
|
||
without: | ||
Refer to the examples folder for guidance on using `liferay-npm-bundler-improved` in a `react`, `vue`, or plain `js` | ||
portlet. | ||
|
||
``` | ||
Error in 0.01s: bundler failed. missing-entry-file-exception: entry file doesn't exist in "build/entry.js". if there is no build step and you need the source entry file, you may want to enable the copy sources option: '--copy-sources' | ||
``` | ||
## advantages | ||
|
||
#### missing css file if `header-portlet-css` is enabled | ||
The main advantages of using `liferay-npm-bundler-improved` are enhanced **speed** and a better **developer experience | ||
**. | ||
|
||
if the `header-portlet-css` option is active and the defined css file can't be found, the bundler doesn't fail but shows | ||
a warning after the build is done. | ||
### speed | ||
|
||
``` | ||
Success in 0.04s: bundler done with one warning | ||
↳ the 'com.liferay.portlet.header-portlet-css' property is set but the according css file can't either be found in 'src/index.css' or in 'build/index.css'. please make sure, the css file is present in one of the directories or remove the property. | ||
``` | ||
The build time for an average portlet with `liferay-npm-bundler-improved` is approximately **0.1s**, regardless of | ||
module size. This represents a significant improvement over the official `liferay-npm-bundler`. | ||
|
||
## missing features | ||
### developer experience | ||
|
||
the current implementation works for most use cases. but there are a few things which aren't currently working as the | ||
original implementation. | ||
`liferay-npm-bundler-improved` offers detailed error reporting, aiding developers in identifying and resolving issues. | ||
Examples include identifying missing keys in `package.json` and detecting missing entry files. | ||
|
||
- package deduplication - _not planned \*\*\*_ | ||
- system configuration - [gathering interest](https://github.com/jwanner83/liferay-npm-bundler-improved/issues/55) \ | ||
↳ portlet instance configuration works since 1.4.0 [#8](https://github.com/jwanner83/liferay-npm-bundler-improved/issues/8) | ||
### deploy mode | ||
|
||
## usage | ||
When the `--deploy` option or `-d` is set, the bundler deploys the portlet to the server after the build, using the path | ||
specified in the `.env` file under `LIFERAY_DEPLOYMENT_PATH`. | ||
|
||
To use the bundler, you have to install it from the `npmjs.org` registry `pnpm i --D liferay-npm-bundler-improved` | ||
and edit your existing build command to use `liferay-npm-bundler-improved` instead of `liferay-npm-bundler`. most of the | ||
features will work out of the box. | ||
### watch mode | ||
|
||
### copy sources | ||
`liferay-npm-bundler-improved` supports a watch mode, allowing automatic portlet rebuilds upon file changes. This is | ||
invaluable for immediate feedback during portlet development. Include the `--watch` option or `-w` in the build command | ||
to enable watch mode. (It is possible to use the `--deploy` option in conjunction with the `--watch` option.) | ||
|
||
if you have `lnbs-copy-sources` inside of your build command, remove it and add `--copy-sources` to the | ||
`liferay-npm-bundler-improved` command. | ||
> [!IMPORTANT] | ||
> The watch mode currently works exclusively with vite as the build tool. It is highly efficient for smaller bundles but | ||
> may not be as effective for larger ones (taking more than 10 seconds to complete). | ||
### copy assets | ||
## missing features | ||
|
||
if you have assets inside the `assets` folder which should be available through the web context url, remove the | ||
`lnbs-copy-assets` command from your existing build command and add `--copy-assets` to the | ||
`liferay-npm-bundler-improved` call | ||
While the current implementation is suitable for most use cases, there are a few features from the original | ||
implementation that are not yet supported: | ||
|
||
### configuration | ||
portlet instance configuration will work the same way as in the official bundler. see the `examples/plain/features/configuration.json` | ||
file for all available options. it is also possible to add translated labels, descriptions and default values with | ||
language keys. the keys have to be defined inside the portlets own localization files. | ||
- Package deduplication (not planned for implementation) | ||
- System configuration - Gathering interest for | ||
implementation ([link](https://github.com/jwanner83/liferay-npm-bundler-improved/issues/55)) | ||
|
||
### examples | ||
<br> | ||
|
||
see the examples folder for an example on how to use the `liferay-npm-bundler-improved` in a `react`, `vue` and plain `js` | ||
portlet. | ||
_\* The official bundler | ||
is [available on GitHub](https://github.com/liferay/liferay-frontend-projects/tree/master/projects/js-toolkit/packages/npm-bundler)_ | ||
|
||
\ | ||
_\* the official bundler is | ||
[available on github](https://github.com/liferay/liferay-frontend-projects/tree/master/projects/js-toolkit/packages/npm-bundler)_ | ||
<br> | ||
_\*\* on a apple m1 macbook pro. on windows it takes about 0.3s._<br> | ||
_\*\*\* the package deduplication feature is currently not planned because of the cost/income ratio. if this feature would be | ||
implemented, the speed of the bundler would decrease a lot and because we didn't use this feature anyway in the company | ||
i worked, i left it out._ | ||
_\*\* Timings are based on an Apple M1 MacBook Pro. On Windows, the timing is approximately 0.3s._ | ||
|
||
_\*\*\* The package deduplication feature is not planned due to its potential impact on bundler speed and the perceived | ||
low usage in practice._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
bin | ||
build | ||
dist | ||
../node_modules | ||
.pnpm-debug.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.