This commit is contained in:
gianlucaguarini 2021-10-24 17:13:56 +02:00
parent 57c28c90d6
commit 141269364e
3 changed files with 267 additions and 562 deletions

View File

@ -1,7 +1,7 @@
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')
/** /**
* Generate the hmr code depending on the tag generated by the compiler * Generate the hmr code depending on the tag generated by the compiler
@ -30,6 +30,10 @@ module.exports = new Transformer({
} }
) )
if (riotConfig && riotConfig.filePath.endsWith('.js')) {
config.invalidateOnStartup()
}
return riotConfig?.contents ?? {} return riotConfig?.contents ?? {}
}, },
async transform({asset, config, options}) { async transform({asset, config, options}) {
@ -40,9 +44,11 @@ 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]

815
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -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": {