https://github.com/hypermedia-app/webpack-loader-rdf
Bundle static RDF documents with webpack
https://github.com/hypermedia-app/webpack-loader-rdf
Last synced: about 1 year ago
JSON representation
Bundle static RDF documents with webpack
- Host: GitHub
- URL: https://github.com/hypermedia-app/webpack-loader-rdf
- Owner: hypermedia-app
- License: mit
- Created: 2021-12-27T15:24:21.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-08T03:19:43.000Z (over 3 years ago)
- Last Synced: 2025-01-04T03:12:21.918Z (over 1 year ago)
- Language: JavaScript
- Size: 203 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# webpack-loader-rdf [](https://npm.im/webpack-loader-rdf)
RDF/JS parsers (and serializers) are quite heavy, only work asynchronously, and depend on various node-native modules, such as `stream` and `crypto`. This can be a nuisance when static RDF is imported early in an application becasue it unnecessarily increases the size of the initial bundle and thus slows down the initial page load.
A webpack loader reserializes RDF into JS code so that it can be bundled along all other sources.
## Usage
```
npm i -D webpack-loader-rdf
```
In `webpack.config.js`
```js
module.exports = {
module: {
rules: [{
test: /\.(ttl|nt|nq|rdf|jsonld|trig)$/,
use: 'webpack-loader-rdf',
}],
}
}
```
In code:
1. Import your favourire [RDF/JS DataFatory](http://rdf.js.org/data-model-spec/#datafactory-interface)
2. Default-import RDF module
3. Combine the two to get a `Quad[]`
```js
import * as $rdf from '@rdf-esm/data-model'
import getPersonQuads from './data/person.ttl`
const personQuads = getPersonQuads($rdf)
```
## In TypeScript
Declare this module, for example in a `global.d.ts`, to get types for Turtle imports
```typescript
declare module '*.ttl' {
import { Quad, DataFactory } from 'rdf-js'
export default function (factory: DataFactory): Quad[]
}
```