Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 91c0f4c0b2 | |||
|
|
8903b91d44 | ||
|
|
552f3af503 | ||
|
|
dff002586d | ||
|
|
141269364e | ||
|
|
57c28c90d6 | ||
|
|
d73842fa0d | ||
|
|
fd04821b33 | ||
|
|
c4ab1cd473 | ||
|
|
2b94698f2f | ||
|
|
d8955bc96b | ||
|
|
b6c95134b4 | ||
|
|
1e04cae511 | ||
|
|
59b84ff83e | ||
|
|
12829a45a8 | ||
|
|
4ee51ea76f | ||
|
|
08e9c11480 | ||
|
|
ab2416bab6 | ||
|
|
5032ed536a | ||
|
|
9a82f62a50 | ||
|
|
bd3ef98534 | ||
|
|
7e2418f3c3 | ||
|
|
e3350f8612 | ||
|
|
2873ca6065 | ||
|
|
212a74fbab | ||
|
|
70747732bd | ||
|
|
0c7d929eaf | ||
|
|
23b9f554ee | ||
|
|
951bd76ecc | ||
|
|
a1a3678838 | ||
|
|
8dfe3239bb | ||
|
|
7f73df104f | ||
|
|
ea1aedd7cf | ||
|
|
97a1479fef |
@ -1,7 +1,7 @@
|
||||
extends: eslint-config-riot
|
||||
|
||||
parserOptions:
|
||||
ecmaVersion: 2018
|
||||
ecmaVersion: 2021
|
||||
sourceType: 'module'
|
||||
|
||||
globals:
|
||||
@ -9,4 +9,4 @@ globals:
|
||||
expect: true
|
||||
|
||||
rules:
|
||||
fp/no-class: false
|
||||
fp/no-class: off
|
||||
|
||||
24
.github/workflows/test.yml
vendored
Normal file
24
.github/workflows/test.yml
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
name: test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, dev ]
|
||||
pull_request:
|
||||
branches: [ dev ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [14.x, 15.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Local Unit Test ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm i
|
||||
- run: npm test
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
node_modules
|
||||
/test/.parcel-cache/
|
||||
/test/package-lock.json
|
||||
/test/dist
|
||||
/test/dist
|
||||
.idea
|
||||
|
||||
14
.travis.yml
14
.travis.yml
@ -1,14 +0,0 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- 10
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- dev
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
|
||||
sudo: false
|
||||
59
Readme.md
59
Readme.md
@ -1,19 +1,32 @@
|
||||
[![Build Status][travis-image]][travis-url]
|
||||
[![Build Status][ci-image]][ci-url]
|
||||
[![NPM version][npm-version-image]][npm-url]
|
||||
[![NPM downloads][npm-downloads-image]][npm-url]
|
||||
[![MIT License][license-image]][license-url]
|
||||
|
||||
A parcel plugin for riot.js
|
||||
The Riot.js official parcel transformer.
|
||||
|
||||
## Important
|
||||
|
||||
If you are using Riot.js < 4.0.0 please check the [v3 branch](https://github.com/riot/parcel-plugin-riot/tree/v3)
|
||||
- If you are using Parcel < 2.0.0 please check the [this branch](https://github.com/riot/parcel-transformer-riot/tree/parcel-v1)
|
||||
- If you are using Riot.js < 4.0.0 please check the [v3 branch](https://github.com/riot/parcel-transformer-riot/tree/v3)
|
||||
|
||||
## Using
|
||||
Add parcel-plugin-riot to your project.
|
||||
|
||||
### 1. Add the riot parcel transformer to your project.
|
||||
|
||||
```bash
|
||||
npm i -D @riotjs/parcel-plugin-riot @riotjs/compiler
|
||||
npm i -D @riotjs/parcel-transformer-riot @riotjs/compiler
|
||||
```
|
||||
|
||||
### 2. Configure your .parcelrc file
|
||||
|
||||
```json
|
||||
{
|
||||
"extends": "@parcel/config-default",
|
||||
"transformers": {
|
||||
"*.riot": ["@riotjs/parcel-transformer-riot"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
-> You are ready!
|
||||
@ -32,12 +45,35 @@ component(App)(document.querySelector('#root'), {
|
||||
If you want compile your tags using custom riot compiler options you can create a `riot.config.js` in the root folder of your project
|
||||
|
||||
```js
|
||||
export default {
|
||||
module.exports = {
|
||||
hot: false // set it to true if you are using hmr
|
||||
// add here all the other @riotjs/compiler options riot.js.org/compiler
|
||||
// template: 'pug' for example
|
||||
}
|
||||
```
|
||||
|
||||
If you want to use `pug` as your template engine, your `riot.config.js` might look like this
|
||||
|
||||
```js
|
||||
const { registerPreprocessor } = require('@riotjs/compiler')
|
||||
const { render } = require('pug')
|
||||
|
||||
// register the pug preprocessor
|
||||
registerPreprocessor('template', 'pug', (code, options) => {
|
||||
const { file } = options
|
||||
|
||||
return {
|
||||
code: render(code, {
|
||||
filename: file,
|
||||
pretty: true,
|
||||
doctype: 'html'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
template: 'pug'
|
||||
}
|
||||
```
|
||||
|
||||
If you want to enable hmr via `hot` option you will need to install also [`@riotjs/hot-reload`](https://www.npmjs.com/package/@riotjs/hot-reload)
|
||||
@ -46,13 +82,14 @@ If you want to enable hmr via `hot` option you will need to install also [`@riot
|
||||
npm i @riotjs/hot-reload -D
|
||||
```
|
||||
|
||||
[travis-image]: https://img.shields.io/travis/riot/parcel-plugin-riot.svg?style=flat-square
|
||||
[travis-url]: https://travis-ci.org/riot/parcel-plugin-riot
|
||||
|
||||
[ci-image]:https://img.shields.io/github/workflow/status/riot/parcel-transformer-riot/test?style=flat-square
|
||||
[ci-url]:https://github.com/riot/parcel-transformer-riot/actions
|
||||
|
||||
[license-image]: https://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
|
||||
[license-url]: LICENSE
|
||||
|
||||
[npm-version-image]: https://img.shields.io/npm/v/parcel-plugin-riot.svg?style=flat-square
|
||||
[npm-downloads-image]: https://img.shields.io/npm/dm/parcel-plugin-riot.svg?style=flat-square
|
||||
[npm-url]: https://npmjs.org/package/parcel-plugin-riot
|
||||
[npm-version-image]: https://img.shields.io/npm/v/@riotjs/parcel-transformer-riot.svg?style=flat-square
|
||||
[npm-downloads-image]: https://img.shields.io/npm/dm/@riotjs/parcel-transformer-riot.svg?style=flat-square
|
||||
[npm-url]: https://npmjs.org/package/@riotjs/parcel-transformer-riot
|
||||
|
||||
|
||||
45
RiotAsset.js
45
RiotAsset.js
@ -1,45 +0,0 @@
|
||||
const { compile } = require('@riotjs/compiler')
|
||||
const { Asset } = require('parcel-bundler')
|
||||
|
||||
/**
|
||||
* Generate the hmr code depending on the tag generated by the compiler
|
||||
* @param {string} path - path to the component file
|
||||
* @returns {string} the code needed to handle the riot hot reload
|
||||
*/
|
||||
function hotReload(path) {
|
||||
return `;(() => {
|
||||
if (module.hot) {
|
||||
const hotReload = require('@riotjs/hot-reload').default
|
||||
module.hot.accept()
|
||||
if (module.hot.data) {
|
||||
const component = require('${path}').default;
|
||||
hotReload(component)
|
||||
}
|
||||
}
|
||||
})()`
|
||||
}
|
||||
|
||||
class RiotAsset extends Asset {
|
||||
constructor(name, pkg, options) {
|
||||
super(name, pkg, options)
|
||||
this.type = 'js'
|
||||
}
|
||||
|
||||
async generate() {
|
||||
const options = (await this.getConfig(['.riotrc', '.riotrc.js', 'riot.config.js'])) || {}
|
||||
const {code, map} = compile(this.contents, {
|
||||
file: this.relativeName,
|
||||
...options
|
||||
})
|
||||
|
||||
return [
|
||||
{
|
||||
sourceMap: this.options.sourceMaps ? map : false,
|
||||
type: 'js',
|
||||
value: `${code}${options.hot ? hotReload(this.relativeName) : ''}`
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RiotAsset
|
||||
64
index.js
64
index.js
@ -1,3 +1,63 @@
|
||||
module.exports = function(bundler) {
|
||||
bundler.addAssetType('riot', require.resolve('./RiotAsset'))
|
||||
const { compile } = require('@riotjs/compiler')
|
||||
const { Transformer } = require('@parcel/plugin')
|
||||
const SourceMap = require('@parcel/source-map').default
|
||||
const { basename } = require('path')
|
||||
|
||||
const CONFIG_FILES = ['.riotrc', '.riotrc.js', 'riot.config.js']
|
||||
const PACKAGE_KEY = 'riot'
|
||||
|
||||
/**
|
||||
* Generate the hmr code depending on the tag generated by the compiler
|
||||
* @param {string} path - path to the component file
|
||||
* @returns {string} the code needed to handle the riot hot reload
|
||||
*/
|
||||
function hotReload(path) {
|
||||
return `;(() => {
|
||||
if (module.hot) {
|
||||
const hotReload = require('@riotjs/hot-reload').default
|
||||
module.hot.accept()
|
||||
if (module.hot.data) {
|
||||
const component = require('./${path}').default;
|
||||
hotReload(component)
|
||||
}
|
||||
}
|
||||
})()`
|
||||
}
|
||||
|
||||
module.exports = new Transformer({
|
||||
async loadConfig({config}) {
|
||||
const riotConfig = await config.getConfig(
|
||||
CONFIG_FILES,
|
||||
{
|
||||
packageKey: PACKAGE_KEY
|
||||
}
|
||||
)
|
||||
const shouldInvalidateOnStartup = riotConfig &&
|
||||
riotConfig?.filePath?.endsWith('.js') ||
|
||||
riotConfig?.filePath?.endsWith(CONFIG_FILES[0])
|
||||
|
||||
if (shouldInvalidateOnStartup) {
|
||||
config.invalidateOnStartup()
|
||||
}
|
||||
|
||||
return riotConfig?.contents ?? {}
|
||||
},
|
||||
async transform({asset, config, options}) {
|
||||
const source = await asset.getCode()
|
||||
const sourceMap = new SourceMap(options.projectRoot)
|
||||
|
||||
const {code, map} = compile(source, {
|
||||
file: asset.filePath,
|
||||
...config
|
||||
})
|
||||
|
||||
// the suffix will be added only for the HMR
|
||||
const suffix = config?.hot ? hotReload(basename(asset.filePath)) : ''
|
||||
|
||||
asset.type = 'js'
|
||||
asset.setCode(`${code}${suffix}`)
|
||||
asset.setMap(sourceMap.addVLQMap(map))
|
||||
|
||||
return [asset]
|
||||
}
|
||||
})
|
||||
|
||||
5520
package-lock.json
generated
5520
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@ -1,24 +1,30 @@
|
||||
{
|
||||
"name": "@riotjs/parcel-plugin-riot",
|
||||
"version": "4.0.0",
|
||||
"description": "A parcel plugin for riot.js",
|
||||
"name": "@riotjs/parcel-transformer-riot",
|
||||
"version": "7.0.2",
|
||||
"description": "The Riot.js official parcel transformer",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"prepare": "npm i --no-save @riotjs/compiler parcel-bundler",
|
||||
"prepare": "npm i --no-save @riotjs/compiler@6 @riotjs/hot-reload@6 riot@6",
|
||||
"test": "npx eslint *.js && npm run test-bundle",
|
||||
"test-bundle": "cd test && npm i"
|
||||
},
|
||||
"engines": {
|
||||
"parcel": "2.x"
|
||||
},
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/andruschka/parcel-plugin-riot"
|
||||
"url": "https://github.com/riot/parcel-plugin-riot"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"parcel-bundler": "^1.12.3",
|
||||
"@riotjs/compiler": "^4.0.0"
|
||||
"@riotjs/compiler": "^6.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^5.16.0",
|
||||
"eslint-config-riot": "^2.0.0"
|
||||
"eslint": "^8.1.0",
|
||||
"eslint-config-riot": "^3.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@parcel/plugin": "^2.0.0",
|
||||
"@parcel/source-map": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
6
test/.parcelrc
Normal file
6
test/.parcelrc
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "@parcel/config-default",
|
||||
"transformers": {
|
||||
"*.riot": ["@riotjs/parcel-transformer-riot"]
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script src="./main.js"></script>
|
||||
<script type="module" src="./main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import MyComponent from './my-component.riot'
|
||||
import { component } from 'riot'
|
||||
|
||||
console.log(MyComponent)
|
||||
|
||||
export default MyComponent
|
||||
component(MyComponent)(document.getElementById('root'))
|
||||
|
||||
@ -1,15 +1,20 @@
|
||||
{
|
||||
"name": "riot-parcel-test",
|
||||
"main": "index.html",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"postinstall": "parcel build index.html --no-cache"
|
||||
},
|
||||
"alias": {
|
||||
"./test/*.riot": "./$1"
|
||||
},
|
||||
"dependencies": {
|
||||
"parcel-bundler": "^1.11.0"
|
||||
"riot": "^6.0.0",
|
||||
"@riotjs/hot-reload": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@riotjs/compiler": "^4.0.0",
|
||||
"@riotjs/parcel-plugin-riot": "file:../"
|
||||
"parcel": "^2.0.0",
|
||||
"@parcel/config-default": "^2.0.0",
|
||||
"@riotjs/compiler": "^6.0.0",
|
||||
"@riotjs/parcel-transformer-riot": "file:../"
|
||||
}
|
||||
}
|
||||
|
||||
3
test/riot.config.js
Normal file
3
test/riot.config.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
hot: true
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user