Compare commits
No commits in common. "main" and "v6.0.0" have entirely different histories.
@ -1,7 +1,7 @@
|
|||||||
extends: eslint-config-riot
|
extends: eslint-config-riot
|
||||||
|
|
||||||
parserOptions:
|
parserOptions:
|
||||||
ecmaVersion: 2021
|
ecmaVersion: 2018
|
||||||
sourceType: 'module'
|
sourceType: 'module'
|
||||||
|
|
||||||
globals:
|
globals:
|
||||||
@ -9,4 +9,4 @@ globals:
|
|||||||
expect: true
|
expect: true
|
||||||
|
|
||||||
rules:
|
rules:
|
||||||
fp/no-class: off
|
fp/no-class: off
|
||||||
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
@ -13,7 +13,8 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [14.x, 15.x]
|
node-version: [10.x, 12.x, 14.x, 15.x]
|
||||||
|
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Local Unit Test ${{ matrix.node-version }}
|
- name: Local Unit Test ${{ matrix.node-version }}
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
/test/.parcel-cache/
|
|
||||||
/test/package-lock.json
|
/test/package-lock.json
|
||||||
/test/dist
|
/test/dist
|
||||||
.idea
|
.idea
|
||||||
|
|||||||
31
Readme.md
31
Readme.md
@ -3,30 +3,17 @@
|
|||||||
[![NPM downloads][npm-downloads-image]][npm-url]
|
[![NPM downloads][npm-downloads-image]][npm-url]
|
||||||
[![MIT License][license-image]][license-url]
|
[![MIT License][license-image]][license-url]
|
||||||
|
|
||||||
The Riot.js official parcel transformer.
|
A parcel plugin for riot.js
|
||||||
|
|
||||||
## Important
|
## Important
|
||||||
|
|
||||||
- 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-plugin-riot/tree/v3)
|
||||||
- If you are using Riot.js < 4.0.0 please check the [v3 branch](https://github.com/riot/parcel-transformer-riot/tree/v3)
|
|
||||||
|
|
||||||
## Using
|
## Using
|
||||||
|
Add parcel-plugin-riot to your project.
|
||||||
### 1. Add the riot parcel transformer to your project.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm i -D @riotjs/parcel-transformer-riot @riotjs/compiler
|
npm i -D @riotjs/parcel-plugin-riot @riotjs/compiler
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Configure your .parcelrc file
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"extends": "@parcel/config-default",
|
|
||||||
"transformers": {
|
|
||||||
"*.riot": ["@riotjs/parcel-transformer-riot"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
-> You are ready!
|
-> You are ready!
|
||||||
@ -83,13 +70,13 @@ npm i @riotjs/hot-reload -D
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
[ci-image]:https://img.shields.io/github/workflow/status/riot/parcel-transformer-riot/test?style=flat-square
|
[ci-image]:https://img.shields.io/github/workflow/status/riot/parcel-plugin-riot/test?style=flat-square
|
||||||
[ci-url]:https://github.com/riot/parcel-transformer-riot/actions
|
[ci-url]:https://github.com/riot/parcel-plugin-riot/actions
|
||||||
|
|
||||||
[license-image]: https://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
|
[license-image]: https://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
|
||||||
[license-url]: LICENSE
|
[license-url]: LICENSE
|
||||||
|
|
||||||
[npm-version-image]: https://img.shields.io/npm/v/@riotjs/parcel-transformer-riot.svg?style=flat-square
|
[npm-version-image]: https://img.shields.io/npm/v/@riotjs/parcel-plugin-riot.svg?style=flat-square
|
||||||
[npm-downloads-image]: https://img.shields.io/npm/dm/@riotjs/parcel-transformer-riot.svg?style=flat-square
|
[npm-downloads-image]: https://img.shields.io/npm/dm/@riotjs/parcel-plugin-riot.svg?style=flat-square
|
||||||
[npm-url]: https://npmjs.org/package/@riotjs/parcel-transformer-riot
|
[npm-url]: https://npmjs.org/package/@riotjs/parcel-plugin-riot
|
||||||
|
|
||||||
|
|||||||
46
RiotAsset.js
Normal file
46
RiotAsset.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
const { compile } = require('@riotjs/compiler')
|
||||||
|
const { Asset } = require('parcel-bundler')
|
||||||
|
const { relative, dirname } = require('path')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(relative(dirname(this.name), this.relativeName)) : ''}`
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = RiotAsset
|
||||||
64
index.js
64
index.js
@ -1,63 +1,3 @@
|
|||||||
const { compile } = require('@riotjs/compiler')
|
module.exports = function(bundler) {
|
||||||
const { Transformer } = require('@parcel/plugin')
|
bundler.addAssetType('riot', require.resolve('./RiotAsset'))
|
||||||
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]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|||||||
19581
package-lock.json
generated
19581
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -1,30 +1,24 @@
|
|||||||
{
|
{
|
||||||
"name": "@riotjs/parcel-transformer-riot",
|
"name": "@riotjs/parcel-plugin-riot",
|
||||||
"version": "7.0.2",
|
"version": "6.0.0",
|
||||||
"description": "The Riot.js official parcel transformer",
|
"description": "A parcel plugin for riot.js",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "npm i --no-save @riotjs/compiler@6 @riotjs/hot-reload@6 riot@6",
|
"prepare": "npm i --no-save @riotjs/compiler@5 parcel-bundler@1 @riotjs/hot-reload@5 riot@5",
|
||||||
"test": "npx eslint *.js && npm run test-bundle",
|
"test": "npx eslint *.js && npm run test-bundle",
|
||||||
"test-bundle": "cd test && npm i"
|
"test-bundle": "cd test && npm i"
|
||||||
},
|
},
|
||||||
"engines": {
|
|
||||||
"parcel": "2.x"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/riot/parcel-plugin-riot"
|
"url": "https://github.com/andruschka/parcel-plugin-riot"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@riotjs/compiler": "^6.0.4"
|
"@riotjs/compiler": "^6.0.0",
|
||||||
|
"parcel-bundler": "^1.9.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.1.0",
|
"eslint": "^7.30.0",
|
||||||
"eslint-config-riot": "^3.0.0"
|
"eslint-config-riot": "^3.0.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@parcel/plugin": "^2.0.0",
|
|
||||||
"@parcel/source-map": "^2.0.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "@parcel/config-default",
|
|
||||||
"transformers": {
|
|
||||||
"*.riot": ["@riotjs/parcel-transformer-riot"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -8,6 +8,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
<script type="module" src="./main.js"></script>
|
<script src="./main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
import MyComponent from './my-component.riot'
|
import MyComponent from './my-component.riot'
|
||||||
import { component } from 'riot'
|
|
||||||
|
|
||||||
|
export default MyComponent
|
||||||
component(MyComponent)(document.getElementById('root'))
|
|
||||||
@ -1,20 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "riot-parcel-test",
|
"name": "riot-parcel-test",
|
||||||
|
"main": "index.html",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "parcel build index.html --no-cache"
|
"postinstall": "parcel build index.html --no-cache"
|
||||||
},
|
},
|
||||||
"alias": {
|
|
||||||
"./test/*.riot": "./$1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"riot": "^6.0.0",
|
"parcel-bundler": "^1.11.0"
|
||||||
"@riotjs/hot-reload": "^6.0.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"parcel": "^2.0.0",
|
"@riotjs/compiler": "^4.0.0",
|
||||||
"@parcel/config-default": "^2.0.0",
|
"@riotjs/hot-reload": "^4.0.0-rc.1",
|
||||||
"@riotjs/compiler": "^6.0.0",
|
"@riotjs/parcel-plugin-riot": "file:../",
|
||||||
"@riotjs/parcel-transformer-riot": "file:../"
|
"riot": "^4.0.0-rc.13"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user