From dff002586d7dc85dedc7626b13ab4a9148eb39b7 Mon Sep 17 00:00:00 2001 From: gianlucaguarini Date: Sun, 24 Oct 2021 17:18:50 +0200 Subject: [PATCH] updated: clean up code base --- index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index f8b336c..60be5c3 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,10 @@ const { compile } = require('@riotjs/compiler') const { Transformer } = require('@parcel/plugin') 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 @@ -24,13 +27,16 @@ function hotReload(path) { module.exports = new Transformer({ async loadConfig({config}) { 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() } @@ -44,6 +50,7 @@ module.exports = new Transformer({ file: asset.filePath, ...config }) + // the suffix will be added only for the HMR const suffix = config?.hot ? hotReload(basename(asset.filePath)) : ''