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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving the JS Asset build pipeline #4328

Closed
bcardarella opened this issue May 15, 2021 · 1 comment 路 Fixed by #4337
Closed

Improving the JS Asset build pipeline #4328

bcardarella opened this issue May 15, 2021 · 1 comment 路 Fixed by #4337

Comments

@bcardarella
Copy link
Contributor

bcardarella commented May 15, 2021

I've already spoken with @chrismccord and got the 馃憤 on this. I'm opening this issue to track progress, indicate what I intend to do, how I intend to implement, and solicit feedback.

What is being addressed

Right now the Webpack build pipeline pulls phoenix.js, phoenix_html.js, and phoenix_live_view.js from their respective Elixir package's deps/<name>/priv/static directories. See this screenshot from the compiled app.js file in a Phoenix 1.5.7 app:

Screen Shot 2021-05-15 at 8 49 12 AM

I've collapsed the code so the source paths are all visible. These files in priv/static are pre-compiled, minified, and obfuscated. Diagnosing app issues or just trying to gain a greater understanding of the JS side of things within an app is incredibly difficult. Adding developer ergonomics like sourcemaps don't make it down to the pre-compiled files. There have been changes to add sourcemaps to the build pipelines that produce these files but that is not the best solution. Instead the current Phoenix environment (dev, prod, test) should dictate how these dependencies are built rather than being pre-built.

In addition, phoenix and phoenix_live_view are published to NPM. However they are included as file reference dependencies in package.json:

Screen Shot 2021-05-15 at 8 54 46 AM

This is fine as it eliminates the need to re-download from NPM. However, each package is set up with the priv/static files at as main in their package.json:

Screen Shot 2021-05-15 at 9 12 36 AM

So when import { Socket } from "phoenix" is called it is matching on the pre-compiled version only. And because the file reference in package.json just sets up a symlink:

Screen Shot 2021-05-15 at 8 56 29 AM

this is why the compiled app.js file references ..deps/<name>/priv/static/<file>.js

There are two possible solutions:

  1. Eliminate the pre-compiled JS files from the dependency packages. I know that part of the reasoning for them is so others that are not using Webpack can consume them. However, I would be interested to know if this is really a concern.
  2. Change main to assets/js in each package

For the sake of causing the least amount of side-effects I'll move forward with the 2nd option for now. I'd like to get feedback on the reality of the 1st though.

@bcardarella
Copy link
Contributor Author

bcardarella commented May 16, 2021

With regards to the existing implementation of SourceMaps... does anyone have this working? According to terser-webpack-plugins own documentation, the currently used setting of eval-cheap-module-source-map is not supported: https://www.npmjs.com/package/terser-webpack-plugin/v/2.3.2#sourcemap

Works only with source-map, inline-source-map, hidden-source-map and nosources-source-map values for the devtool option.

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

Successfully merging a pull request may close this issue.

1 participant