Frontend: External Assets
Pakyow provides a simple way to manage external JavaScript in your apps, without the bloat of a tool like NPM or Yarn. These tools can be great for complex build pipelines, but Pakyow's simpler approach is a good fit for most applications.
External scripts are defined in your application's configure
block:
Pakyow.app do
configure do
external_script :d3
end
end
The next time the project is started in development mode, Pakyow will fetch a browser-ready build of the D3.js library, placing it into the frontend/packs/vendor
folder. D3 can be loaded like any other pack:
---
packs:
- d3
---
...
Any package hosted on NPM can be managed in this way, as long as it provides a browser-ready build for distribution. Pakyow currently fetches external scripts from the unpkg.com service.
Working with package version
When an external package version is left unspecified, as in the previous example, Pakyow will download the latest available version. To specify a specific version, simply define it when registering the external package:
Pakyow.app do
configure do
external_script :d3, "5.5.0"
end
end
The version can be any semvar value supported by NPM. Read more →
Specifying the package name
Sometimes the name of the external package is not the most logical name to use within your application. For example, the Pakyow.js pack lives in a package named @pakyow/js
but is exposed through the pakyow
pack.
Pakyow can handle these cases with the package
argument:
Pakyow.app do
configure do
external_script :pakyow, package: "@pakyow/js"
end
end
Here the given name pakyow
is used to name the pack available within the application, while @pakyow/js
is the name of the external package to be fetched from NPM.
Updating external assets
Use the pakyow assets:update
command to update external assets:
pakyow assets:update