refactor: closer to server HMR...
This commit is contained in:
parent
11977f77b4
commit
0866fa8cbf
|
@ -30,7 +30,7 @@ module.exports = {
|
||||||
}),
|
}),
|
||||||
mocha(),
|
mocha(),
|
||||||
node({
|
node({
|
||||||
hot: false,
|
hot: true,
|
||||||
}),
|
}),
|
||||||
(neutrino) => {
|
(neutrino) => {
|
||||||
[
|
[
|
||||||
|
@ -65,7 +65,7 @@ module.exports = {
|
||||||
}]);
|
}]);
|
||||||
neutrino.config
|
neutrino.config
|
||||||
.entry('index')
|
.entry('index')
|
||||||
.prepend('@latus/core/start');
|
.add('@latus/core/start');
|
||||||
if ('production' !== neutrino.config.get('mode')) {
|
if ('production' !== neutrino.config.get('mode')) {
|
||||||
neutrino.config
|
neutrino.config
|
||||||
.entry('index')
|
.entry('index')
|
||||||
|
@ -74,6 +74,7 @@ module.exports = {
|
||||||
.plugin('start-server')
|
.plugin('start-server')
|
||||||
.tap((args) => {
|
.tap((args) => {
|
||||||
const options = args[0];
|
const options = args[0];
|
||||||
|
options.signal = true;
|
||||||
const inspectArg = process.argv.find((arg) => -1 !== arg.indexOf('--inspect'));
|
const inspectArg = process.argv.find((arg) => -1 !== arg.indexOf('--inspect'));
|
||||||
if (inspectArg) {
|
if (inspectArg) {
|
||||||
options.nodeArgs.push(inspectArg);
|
options.nodeArgs.push(inspectArg);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import {LatusPlugin} from './latus-plugin';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
unique as arrayUnique,
|
unique as arrayUnique,
|
||||||
flatten as arrayFlatten,
|
flatten as arrayFlatten,
|
||||||
|
@ -9,15 +11,68 @@ export {default as EventEmitter} from './event-emitter';
|
||||||
export {deflate, inflate} from './flate';
|
export {deflate, inflate} from './flate';
|
||||||
export {compose, fastApply} from './function';
|
export {compose, fastApply} from './function';
|
||||||
export {decorateWithLatus, gatherWithLatus, default as gather} from './gather';
|
export {decorateWithLatus, gatherWithLatus, default as gather} from './gather';
|
||||||
export {LatusPlugin} from './latus-plugin';
|
|
||||||
export {default as Middleware} from './middleware';
|
export {default as Middleware} from './middleware';
|
||||||
export {default as Latus} from './latus';
|
export {default as Latus} from './latus';
|
||||||
export * from './string';
|
export * from './string';
|
||||||
|
|
||||||
|
export {LatusPlugin};
|
||||||
|
|
||||||
export const Class = class {};
|
export const Class = class {};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
hooks: {
|
hooks: {
|
||||||
|
'@latus/core/build': (configs, latus) => {
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
configs.app.use.unshift((neutrino) => {
|
||||||
|
const defaults = Object.keys(latus.originalConfig)
|
||||||
|
.map((plugin) => {
|
||||||
|
const config = {};
|
||||||
|
[plugin, `${plugin}/server`].forEach((path) => {
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line no-eval
|
||||||
|
eval('require.resolve')(path);
|
||||||
|
config[path] = {};
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line no-empty
|
||||||
|
catch (error) {}
|
||||||
|
});
|
||||||
|
return config;
|
||||||
|
})
|
||||||
|
.filter((config) => !!config)
|
||||||
|
.reduce((r, o) => ({...r, ...o}), {});
|
||||||
|
const config = Object.fromEntries(
|
||||||
|
Object.keys(defaults)
|
||||||
|
.map((path) => [
|
||||||
|
path,
|
||||||
|
latus.get(path),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
neutrino.config
|
||||||
|
.plugin('latus')
|
||||||
|
.use(LatusPlugin(
|
||||||
|
neutrino,
|
||||||
|
() => config,
|
||||||
|
(plugin, modulesObject) => {
|
||||||
|
plugin.writeModule('/%/latus/server/virtual', [
|
||||||
|
'global.$$latus = {',
|
||||||
|
` config: ${JSON.stringify(config)},`,
|
||||||
|
` modules: ${modulesObject},`,
|
||||||
|
'};',
|
||||||
|
'if (module.hot) {',
|
||||||
|
' Object.keys(global.$$latus.modules).forEach((key) => {',
|
||||||
|
' module.hot.accept(key, () => {',
|
||||||
|
" console.log('kesy!');",
|
||||||
|
' });',
|
||||||
|
' });',
|
||||||
|
'}',
|
||||||
|
].join('\n'));
|
||||||
|
},
|
||||||
|
));
|
||||||
|
neutrino.config
|
||||||
|
.entry('index')
|
||||||
|
.add('/%/latus/server/virtual');
|
||||||
|
});
|
||||||
|
},
|
||||||
'@latus/core/config': () => ({
|
'@latus/core/config': () => ({
|
||||||
id: 'latus',
|
id: 'latus',
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -22,7 +22,8 @@ exports.LatusPlugin = (neutrino, getConfig, write) => class LatusPlugin {
|
||||||
});
|
});
|
||||||
compiler.hooks.beforeCompile.tapPromise('LatusPlugin', async () => {
|
compiler.hooks.beforeCompile.tapPromise('LatusPlugin', async () => {
|
||||||
const paths = Object.keys(await getConfig())
|
const paths = Object.keys(await getConfig())
|
||||||
.map((path) => Latus.runtimePath(path));
|
.map((path) => Latus.runtimePath(path))
|
||||||
|
.filter((path) => !!path);
|
||||||
const pathMap = paths.map((path) => `'${path}': require('${path}')`).join(', ');
|
const pathMap = paths.map((path) => `'${path}': require('${path}')`).join(', ');
|
||||||
write(plugin, `{${pathMap}}`, paths);
|
write(plugin, `{${pathMap}}`, paths);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
|
/* eslint-disable no-console */
|
||||||
import Latus from './latus';
|
import Latus from './latus';
|
||||||
|
|
||||||
process.stdout.write('Latus starting...\n');
|
console.log('Latus starting...');
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const latus = Latus.create();
|
const latus = new Latus(global.$$latus);
|
||||||
try {
|
try {
|
||||||
await Promise.all(latus.invokeFlat('@latus/core/starting'));
|
await Promise.all(latus.invokeFlat('@latus/core/starting'));
|
||||||
await Promise.all(latus.invokeFlat('@latus/core/started'));
|
await Promise.all(latus.invokeFlat('@latus/core/started'));
|
||||||
await latus.invokeSequential('@latus/core/server/up');
|
await latus.invokeSequential('@latus/core/server/up');
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('Latus up!');
|
console.log('Latus up!');
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user