Themes
Last updated
Was this helpful?
Last updated
Was this helpful?
The project introduces the concept of "themes".
For application to be considered a theme, it must have a package.json
field scandipwa.type
equal to theme
. For example:
The theme is what you compile into running website, therefore it also contains start
and build
scripts. You can read more about them in the "" section.
Themes can stack on top of each another. A theme which another theme is based on is called a parent theme. To specify a parent theme, set the package.json
field scandipwa.parentTheme
equal to intended parent theme package name.
If you are selecting a new parent theme, it is not enough to just set the value of scandipwa.parentTheme
in package.json
. The parent theme package should be listed among of your package dependencies
.
The properly installed parent theme package.json
could look like this:
In previous versions of ScandiPWA, the import from parent theme looked the following way:
You may have noticed the SourceComponent
alias appearing in the begging of the import. This allows to define shorter import paths. This alias is composed from a folder inside of the src
and the prefix of the theme. The @scandipwa/scandipwa
theme has a prefix Source
. The src
folders which support this mapping are:
Folder alias
Path from theme root
Purpose
Style
./src/style
Global styles
Component
./src/component
React component definitions
Route
./src/route
Router pages definitions
Util
./src/util
Utility functions
Query
./src/query
GraphQL query definitions
Type
./src/type
React prop-type definitions
Store
./src/store
Redux store definitions
To define a Webpack alias for your theme, you are required to define the scandipwa.themeAlias
field in package.json
. The value you define in this field will be used as your theme prefix. You can do it like this:
There is however, another way to import files from a parent theme. You can always import the file from the NPM package of your parent theme directly. Like so:
Both of these approaches are valid, but for consistency, we recommend using Webpack aliases.
A theme can override files of a parent theme. Learn more about overriding a parent theme in the guide.