updated: clean up code base
This commit is contained in:
parent
141269364e
commit
dff002586d
15
index.js
15
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 { basename } = 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,13 +27,16 @@ 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 (riotConfig && riotConfig.filePath.endsWith('.js')) {
|
if (shouldInvalidateOnStartup) {
|
||||||
config.invalidateOnStartup()
|
config.invalidateOnStartup()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +50,7 @@ module.exports = new Transformer({
|
|||||||
file: asset.filePath,
|
file: asset.filePath,
|
||||||
...config
|
...config
|
||||||
})
|
})
|
||||||
|
|
||||||
// the suffix will be added only for the HMR
|
// the suffix will be added only for the HMR
|
||||||
const suffix = config?.hot ? hotReload(basename(asset.filePath)) : ''
|
const suffix = config?.hot ? hotReload(basename(asset.filePath)) : ''
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user