Below is my Firebase hosting project folder structure:
projectFolder/store/public/scripts/*.min.js
projectFolder/src/*.js
After running terser, all my projectFolder/src/*.js will be minified to projectFolder/store/public/scripts/*.min.js as shown below:
EDIT: As requested by @Bergi, this is how my terser script looks like:
call terser src/site-ui-components.js -o store/public/scripts/site-ui-components.min.js -c -m
echo site-ui-components.min.js: Done.
call terser src/login.js -o store/public/scripts/login.min.js -c -m
echo login.min.js: Done.
call terser src/register.js -o store/public/scripts/register.min.js -c -m
echo register.min.js: Done.
call terser src/profile.js -o store/public/scripts/profile.min.js -c -m
echo profile.min.js: Done.
In my ES6 import, I do the following:
import { something1, something2 } from "/scripts/something.min.js";
This works fine during runtime, but I lose all the vs code intellisense for something1 and something2 during development time. If I enable the intellisense by doing the following, during runtime, my code breaks because obviously, it couldn't find "./something.js":
import { something1, something2 } from "./something.js"; // Error, something.min.js not found
I do not want to do something silly by adding the *.min.js to my all my non-minified js just to make both of them work. Secondly, I try to avoid using dynamic import by writing extra code to adapt to different environment.
So my question is:
- How can I keep my intellisense for ES6 import without breaking my code during runtime?
- Is there something wrong with my folder structure? E.g. not compliant to the best/common practice? Any recommendation?
- Shall I, might as well, make the minified and non-minified js files as simply
*.jsinstead?
Any advice would be much appreciated. Thank you!
After so much of searching and reading, I finally managed to figure out the use of
baseUrlandpathsofjsconfig.jsonin VS Code to solve my problems:Explanations:
The goal here is to make the following import works for both
/src/*.jsand/store/public/scripts/*.min.jswithout losing the inteliisense:For my case, it doesn't really matter if my JS in
srcreferences to/scripts/*.min.jsbecause*.min.jsare always getting from the latest object interfaces from thesrc. Whenever I change any JS file in thesrc, I just run myterserscript for the new changes to be reflected by the intellisense, so not a big deal. Therefore, in order for both/src/*.jsand/scripts/*.min.jsto import from the same source without breaking the code during runtime, I can configure myjsconfig.jsonas shown above to achieve this goal:The
"."is theprojectFolderwhere myjsconfig.jsonis stored, namelyprojectFolder/jsconfig.json."/scripts/*"is the string pattern or import path that I use to reference the exported module files. So when Iimport { something1 } from "/scripts/something.min.js", VS Code always refers to"./store/public/scripts/*"for the intellisense.I hope my explanation is clear to everyone.