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

Use Webpack Encore #6823

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft

Conversation

yguedidi
Copy link
Contributor

@yguedidi yguedidi commented Aug 10, 2023

This PR is doing multiple things that could be extracted in separated PR later if you want.
I'm opening it as draft so that you can have a look at it, and so that we can start taking decisions and drafting solutions to the issues I faced.

What this PR is about more precisely:

  • some assets clean up
  • merge of global and material as no more theming
  • follow standard convetions (root assets/ folder, build/ instead of wallassets)
  • simplify Webpack config by using Webpack Encore
  • better builds following Webpack Encore sane defaults (but some tweaks to fit with Wallabag needs)

edit: found a solution, see #6823 (comment)

It's really almost done and it actually works!
But there is one thing that is a blocker: the fact that production generated assets are tracked in the repository.
Why is that an issue: Webpack Encore relies mainly on 2 files, manifest.json and entrypoints.json
It's possible to have different manifests for prod and dev (what I did already), but for entrypoints.json it's not possible.
And this leads to the fact that the file is changed when running dev build or watch. Not a super DX, see commit [WIP] issue after dev build for what happen after to the tracked entrypoints.json

So what would be the right direction in your option?
To me, production generated assets shouldn't be tracked in the dev repository.
But I guess the docker image and ZIP packages rely on that so not that simple to manage the production assets building step outside the repository. Am I right here?

Feel free to tell me what you accept that I extract in a separated PR, because the folder structure changes are not impacted by the issue mentionned above, just the use of Webpack Encore

@yguedidi yguedidi marked this pull request as ready for review August 12, 2023 00:06
@yguedidi
Copy link
Contributor Author

Managed to find a solution! 🎉
It may look a bit "hacky" (and I personally think it is), but it works the way Wallabag works today, by having generated production assets be part of the source code.
I used the possibility to have multiple webpack builds to solve the issue, one build for prod in a public folder that is tracked by git, and another build for dev generated in another folder that is not tracked by git.
Not sure this feature was made for that usage but it's OK for now I would say!
The cleaner solution not having production assets in the source code is another topic to be solved later.

Comment on lines +6 to +7
"useBuiltIns": "usage",
"corejs": "3.23"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -59,3 +59,5 @@ specialexport.json

# Custom CSS file
web/custom.css

yarn-error.log
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -58,6 +60,7 @@
"postcss": "^8.4.27",
"postcss-loader": "^7.3.3",
"postcss-scss": "^4.0.6",
"regenerator-runtime": "^0.14.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"webpack-manifest-plugin": "^5.0.0",
"webpack-merge": "^5.9.0"
"webpack-merge": "^5.9.0",
"webpack-notifier": "^1.15.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"autoprefixer": "^10.4.14",
"babel-loader": "^9.1.3",
"core-js": "^3.32.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -70,9 +73,9 @@
"url-loader": "^4.1.1",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

will still be installed as a transitive dependency

Comment on lines +1 to +5
module.exports = {
plugins: {
autoprefixer: {},
},
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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


{{ encore_entry_link_tags('public', null, app.environment == 'dev' ? 'dev' : 'prod') }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now test environment is using prod assets that are generated.
did this change because on CI dev assets are not generated, and it can happen that on dev we don't have them neither, so using prod assets ensure we don't have assets missing errors when running tests

Comment on lines +12 to +13
.splitEntryChunks()
.enableSingleRuntimeChunk()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +46 to +53
.configureImageRule({
type: 'asset',
maxSize: 500 * 1024, // see https://github.com/symfony/webpack-encore/issues/1132
})
.configureFontRule({
type: 'asset',
maxSize: 500 * 1024, // see https://github.com/symfony/webpack-encore/issues/1132
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

asset/inline is not working, so here a trick to force inlining images and fonts

Copy link
Member

@j0k3r j0k3r left a comment

Choose a reason for hiding this comment

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

We are tracking prod asset into Git because we don't want end user to install node, yarn, etc.. to build asset on their side.
If assets are ready from the repo, it's way much easier for us. We do already have a lot of request because of server installation problem and we don't want to add more with the installation of node, etc 😬


/* Shortcuts */

/* Go to */
Copy link
Member

Choose a reason for hiding this comment

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

Is that coming from a deleted file?

Copy link
Member

Choose a reason for hiding this comment

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

Won't the name change each time the file is built?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, but as the goal is to remove prod built assets from the repo the build folder will be ignored :)

@yguedidi
Copy link
Contributor Author

We are tracking prod asset into Git because we don't want end user to install node, yarn, etc.. to build asset on their side.

@j0k3r I completely understand! but having them in the development repository and having them in the en user release ready to be used it's not the name :)
see for example wallabag/docker#362 where the assets are built in the Docker image directly.
a similar thing can be done when creating an archive release.

@j0k3r
Copy link
Member

j0k3r commented Aug 24, 2023

a similar thing can be done when creating an archive release.

You are totaly right, this can be done when we create the archive ready to be installed and attached to each release.
But then, we'll need to improve the documentation about installing tools (node, yarn, etc.) to build assets locally when people only clone the repository.

@yguedidi yguedidi marked this pull request as draft August 26, 2023 08:55
@yguedidi
Copy link
Contributor Author

@j0k3r for reference there are wallabag/docker#362 for Docker and #6982 for ZIP releases that build assets on the fly for those artifacts.
once accepted we will be able to remove built assets from the git repository!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants