diff --git a/packages/core/src/build.js b/packages/core/src/build.js index 8c470eb..67a5e1e 100644 --- a/packages/core/src/build.js +++ b/packages/core/src/build.js @@ -80,9 +80,9 @@ export default (latus) => (neutrino) => { '};', 'if (module.hot) {', ]; - paths.forEach((key) => { - source.push(` module.hot.accept('${key}', () => {`); - source.push(` global.latus.invoke('@latus/core/hmr', '${key}');`); + paths.forEach((path) => { + source.push(` module.hot.accept('${path}', () => {`); + source.push(` global.latus.invoke('@latus/core/hmr', '${path}');`); source.push(' });'); }); source.push('}'); diff --git a/packages/http/src/build/neutrino/virtual.js b/packages/http/src/build/neutrino/virtual.js index 23a8ad3..a088322 100644 --- a/packages/http/src/build/neutrino/virtual.js +++ b/packages/http/src/build/neutrino/virtual.js @@ -1,3 +1,4 @@ +const {statSync} = require('fs'); const { basename, dirname, @@ -28,7 +29,6 @@ module.exports = async (latus) => { .map((path) => Latus.runtimePath(`${path}/index.css.js`)) .filter((path) => !!path); const cssAppliers = cssPaths.map((path) => `require('${path}')`).join(';'); - const virtual = R.resolve('@latus/http/virtual'); const source = [ `${cssAppliers}`, 'export default {', @@ -37,12 +37,33 @@ module.exports = async (latus) => { '};', ]; source.push('if (module.hot) {'); - paths.forEach((key) => { - source.push(` module.hot.accept('${key}', () => {`); - source.push(` window.latus.invoke('@latus/core/hmr', '${key}');`); + const copy = R('@neutrinojs/copy'); + const contexts = new Set(); + paths.forEach((path) => { + source.push(` module.hot.accept('${path}', () => {`); + source.push(` window.latus.invoke('@latus/core/hmr', '${path}');`); source.push(' });'); + const context = join(dirname(R.resolve(path)), 'assets'); + if (contexts.has(context)) { + return; + } + contexts.add(context); + try { + statSync(context); + copy({ + patterns: [{ + context, + from: join('**', '*'), + to: 'assets', + }], + pluginId: path, + })(neutrino); + } + // eslint-disable-next-line no-empty + catch (error) {} }); source.push('}'); + const virtual = R.resolve('@latus/http/virtual'); neutrino.config.module .rule(virtual) .test(virtual)