https://github.com/architect/plugin-bundle
https://github.com/architect/plugin-bundle
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/architect/plugin-bundle
- Owner: architect
- Created: 2021-06-16T20:45:32.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-06-16T20:46:52.000Z (almost 5 years ago)
- Last Synced: 2025-02-25T07:16:09.350Z (over 1 year ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# @architect/plugin-bundle
Automatically bundle `@views` into `/public/bundles`.
```bash
npm install @architect/plugin-bundle
```
## Usage
Add to `app.arc`:
```arc
# app.arc
@app
myapp
@http
get /
@static
ignore bundles
@plugins
architect/plugin-bundle
```
Add a script tag to your HTML:
```html
```
The following will happen:
- We look for the requested origin file in `@views` (in this example case `src/views/path/to/file.js`)
- If it has already been bundled and if so return that path
- Otherwise it will bundle it with all its deps and write to s3
- Browser is redirected to the bundled file
If you want to avoid the redirect you can call entry at runtime in your Lambda function code. Cache the bundled result outside the function handler for the best performance:
```javascript
let entry = require('@architect/plugin-bundle')
let cache = false
exports.handler = async function http (req) {
// get the path to bundled file
if (cache === false)
cache = await entry('/path/to/file.js')
// dynamic render html
return {
statusCode: 200,
headers: {
'content-type': 'text/html; charset=utf8'
},
body: `
my cool html here
`
}
}
```