Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 91c0f4c0b2 | |||
|
|
8903b91d44 | ||
|
|
552f3af503 | ||
|
|
dff002586d | ||
|
|
141269364e | ||
|
|
57c28c90d6 | ||
|
|
d73842fa0d |
@ -3,7 +3,7 @@
|
|||||||
[![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]
|
||||||
|
|
||||||
A parcel plugin for riot.js
|
The Riot.js official parcel transformer.
|
||||||
|
|
||||||
## Important
|
## Important
|
||||||
|
|
||||||
|
|||||||
21
index.js
21
index.js
@ -1,7 +1,10 @@
|
|||||||
const { compile } = require('@riotjs/compiler')
|
const { compile } = require('@riotjs/compiler')
|
||||||
const { Transformer } = require('@parcel/plugin')
|
const { Transformer } = require('@parcel/plugin')
|
||||||
const SourceMap = require('@parcel/source-map').default
|
const SourceMap = require('@parcel/source-map').default
|
||||||
const { relative } = require('path')
|
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
|
* Generate the hmr code depending on the tag generated by the compiler
|
||||||
@ -24,11 +27,18 @@ function hotReload(path) {
|
|||||||
module.exports = new Transformer({
|
module.exports = new Transformer({
|
||||||
async loadConfig({config}) {
|
async loadConfig({config}) {
|
||||||
const riotConfig = await config.getConfig(
|
const riotConfig = await config.getConfig(
|
||||||
['.riotrc', '.riotrc.js', 'riot.config.js'],
|
CONFIG_FILES,
|
||||||
{
|
{
|
||||||
packageKey: 'riot'
|
packageKey: PACKAGE_KEY
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
const shouldInvalidateOnStartup = riotConfig &&
|
||||||
|
riotConfig?.filePath?.endsWith('.js') ||
|
||||||
|
riotConfig?.filePath?.endsWith(CONFIG_FILES[0])
|
||||||
|
|
||||||
|
if (shouldInvalidateOnStartup) {
|
||||||
|
config.invalidateOnStartup()
|
||||||
|
}
|
||||||
|
|
||||||
return riotConfig?.contents ?? {}
|
return riotConfig?.contents ?? {}
|
||||||
},
|
},
|
||||||
@ -40,9 +50,12 @@ module.exports = new Transformer({
|
|||||||
file: asset.filePath,
|
file: asset.filePath,
|
||||||
...config
|
...config
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// the suffix will be added only for the HMR
|
||||||
|
const suffix = config?.hot ? hotReload(basename(asset.filePath)) : ''
|
||||||
|
|
||||||
asset.type = 'js'
|
asset.type = 'js'
|
||||||
asset.setCode(`${code}${config?.hot ? hotReload(relative(options.projectRoot, asset.filePath)) : ''}`)
|
asset.setCode(`${code}${suffix}`)
|
||||||
asset.setMap(sourceMap.addVLQMap(map))
|
asset.setMap(sourceMap.addVLQMap(map))
|
||||||
|
|
||||||
return [asset]
|
return [asset]
|
||||||
|
|||||||
819
package-lock.json
generated
819
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@riotjs/parcel-transformer-riot",
|
"name": "@riotjs/parcel-transformer-riot",
|
||||||
"version": "7.0.0",
|
"version": "7.0.2",
|
||||||
"description": "The Riot.js official parcel transformer",
|
"description": "The Riot.js official parcel transformer",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -17,10 +17,10 @@
|
|||||||
"url": "https://github.com/riot/parcel-plugin-riot"
|
"url": "https://github.com/riot/parcel-plugin-riot"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@riotjs/compiler": "^6.0.0"
|
"@riotjs/compiler": "^6.0.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.30.0",
|
"eslint": "^8.1.0",
|
||||||
"eslint-config-riot": "^3.0.0"
|
"eslint-config-riot": "^3.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user