Skip to content

A) Directory structure

Damien Maillard edited this page May 1, 2024 · 13 revisions

This page shows how directory and files can be organized while using jsenv.
A few key directories and files are introduced like "source files" and "build files":

project/       -> root directory
  dist/        -> build files will be written here
  scripts/     -> executable files
  src/         -> sources files
  package.json  

Please note it's an example: jsenv impose zero constraints on your project structure.
It works with directory containing multiples packages enabled by NPM workspaces for example.

With a few files it gives the following result:

project/          
  dist/           
    index.html
  scripts/
    build.mjs
    dev.mjs
    test.mjs
  src/
    index.html
  package.json

scripts/ contains files executable directly with node command.

File Description Link to doc
dev.mjs starts a dev server for files in src/ B) Dev
build.mjs optimize files from src/ and write then into dist/ C) Build
test.mjs execute test files D) Test

You can execute these files directory with node:

node ./scripts/dev.mjs

In general it's recommended to execute files via an alias.
To achieve this, the following can be added to package.json:

"scripts": {
  "dev": "node ./scripts/dev.mjs",
  "build": "node ./scripts/build.mjs",
  "test": "node ./scripts/test.mjs"
}

Allowing to execute files using NPM as follows:

npm run dev
npm run build
npm run test
> B) Dev