- react: all the cool kids are doing it
- typescript: business in the front, party in the back
- antd: the best thing to come out of China since the fork
- ts-force: generates massive files so you don't have toooo
- vite: Does a lot of stuff won't ever fully don't understand, slightly better than webpack
- sfdx-cli: #nosoftware
- develop w/ local asset on VisualForce page
- Hot Module Reloading (HMR)!
- 1 step build & deploy to orgs
- supports developer, sandbox, scratch and production orgs
- type safety and code completion when working with SF objects
- testing with vitest
- setup for debugging in vscode chrome debugger
Make sure you have the following installed on your machine:
npm
- sfdx-cli: If you plan on developing against "scratch orgs", you will need to authorize a "hub".
You will also need the ability to execute the following bash commands: zip
, cp
, mv
.
There are several options:
- A
bash
enumerator (like the one included withgit
). You may need to installzip
binaries - linux
- mingw
You may also need to tell npm to use bash: npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe"
First, install Yeoman and generator-bass using npm (we assume you have pre-installed node.js).
npm install -g yo
npm install -g generator-bass
Then generate your new project:
yo bass my-project
# ... answer questions
cd my-project
npm run deploy-dev # this will deploy code to your dev target org
app
: The react Application source Folderforce-app
: The Salesforce DX package. Store related metadata here. You can change this via yeoman promptconfig
: configurations for development, build & tests (some configuration files are in root)dist
: the build directory
To do much of anything you'll need to connect with one or more orgs. Use sfdx force:org:list
to see a list of orgs you're already authenticated with. Connect to an existing sandbox using sfdx force:auth:web:login -sr [ORG_URL] -a [ALIAS]
. You can also create a scratch org using: npm run new-scratch-org
.
The starter supports 3 pre-defined "targets". Each target allow us to run different build & dev scripts
depending on the context:
dev
: to develop against a traditional salesforce org. Developer or Sandbox.scratch
: allows development against a "scratch org" using the Salesforce DX flow. Must authenticate with a "hub org"prod
: to release your app. Optimizes build
Targets are set in the .npmrc
config file. You can use either the alias or the username here:
dev_alias=dev_username
scratch_alias=scratch
prod_alias=john@acme.com
*NOTE: You might want to ignore .npmrc
for your repo. Each contributor will manage this configuration separately and committing it could result in another user accidentally deploying to an unintended org. This is especially true if you use the sfdx alias over the username
- Deploy your application by running
npm run deploy-dev
ornpm run deploy-scratch
. This step needs to happen whenever the contents offorce-app
change. - run
npm start
- Enable the
Allow Insecure Localhost
setting in chrome (chrome://flags/#allow-insecure-localhost). If you don't want to enable this, or use a different browser, you can create your own self-signed certificate by following these instructions. - navigate to your page in salesforce: EG:
/apex/app
- append
?local=1
to page query string - Start coding. Your app will automatically update as you save changes.
vite
compiles and makes your app available @ https//localhost:PORT
. It incrementally compiles your app as you make changes allows modules to be hot reloaded without refreshing the page.
You can see how this is configured by looking at force-app/main/default/pages/App.page
. Basically, we just have two output panels that render conditionally based on the url param local == 1
.
This starter offers 1 step build & deploy to each of the 3 targets.
npm run deploy-dev
npm run deploy-scratch
npm run deploy-prod
This diagram outlines the process.
Renaming the page is as simple as navigating to force-app/main/default/pages
and renaming the app.page
and app.page-meta.xml
to whatever you want.
Note: You can have multiple VF pages
- in
package.json
, under theconfig
section, updateresource
- optionally, update your
.gitignore
to exclude these files - finally, just update
$Resource.app
in the vf page to properly reference the new resource name
**NOTE: If you include other static resources in the force-app/main/default/staticresources
folder they will get nuked by default. To prevent this, update the copy-bundle
script **
This project comes equipped with ts-force
to allow you typed access to Salesforce Rest API. To use ts-force
, you must first generate classes for the SObjects you want to work with.
You can do this by editing ts-force-config.json
. Make sure auth: {username: ""}
is set to the target org alias you want to use to generate classes. This should be the end user for the app!
For more details on configuration, see the ts-force documentation.
Unfortunately the port isn't currently managed from a single point and must be updated in 2 places:
- in
.npmrc
, under thedevServerPort
section - in
/force-app/main/default/pages/App.Page
, update the "Local Asset" panel:https://localhost:XXXX/app.js
.
TIP: If you need multiple devs working on different ports, update the page to pull port from a custom setting!
It is possible to debug right from vscode. To do so:
- install Debugger for Chrome
- update
.vscode/launch.json
->url
to reference the url you want to debug npm start
f5
or launchdebug locally
configuration- you may need to Enable Allow Insecure Localhost again if it opens in a different instance of chrome
Overtime, this project has gotten both simpler AND objectively better.
Unfortunately upgrades are currently a very manual process. Overtime:
- configuration files have been changed & moved around
- Low Value / High Complexity: features have been removed
- build scripts have changed
- configuration files have changed
- npm dependencies have been upgraded/added/removed
I admit, I haven't done a very good job of documenting these changes very well. My goal of keeping this everything as flexible as possible has also made it impossible to move parts of the configuration to upgradable packages.
Version 2.0.0 is a major upgrade to the project. It includes the following changes:
- Upgrade to React18
- Replace Webpack with Vite
- Replacing Jest/Enzyme with Vitest/React Testing Library
- Upgrade to antd v5 (changes to theming, removes LESS support by default)
The easiest way to upgrade is to start a new project and copy over your files.
Highly recommend using vscode (typescript code completion, in editor terminal, etc).
plugins:
- Editor Config: auto-set formatting options for everyone
- TSlint: green squigglies everywhere!
- Salesforce Extensions for VS Code: gives your code completion on your
force-app
and ability to excute commands against the CLI - ViTest: run tests in vscode
- typescript deep dive
- react-redux-typescript-guide
- vite reference
- vitest reference
- sfdx cli reference
- Where to Hold React Component Data: state, store, static, and this
- Redux: How to chain async actions
- a-redux-typescript-setup
- Idiomatic Redux: Thoughts on Thunks, Sagas, Abstraction, and Reusability
Copyright (c) 2017 Charlie Jonas charlie@callaway.cloud
Expanded from react-redux-typescript-webpack-starter
Copyright (c) 2016 Piotr Witek piotrek.witek@gmail.com (http://piotrwitek.github.io/)