You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

const {
__DEV__,
backendBuildPath,
} = require('../environment');
if (__DEV__) {
const webpack = require('webpack');
const webpackConfig = require('../webpack.backend.config.js');
const compiler = webpack(webpackConfig);
let backend = null;
let lastHash = null;
compiler.watch({
watchOptions: {
ignored: /public/,
},
}, (err, stats) => {
if (err) {
lastHash = null;
compiler.purgeInputFileSystem();
console.error(err);
} else if (stats.hash !== lastHash) {
lastHash = stats.hash;
console.info(stats.toString({
cached: false,
colors: true,
}));
delete require.cache[require.resolve(backendBuildPath)];
backend = require(backendBuildPath).default;
}
});
const backendWrapper = (req, res, next) => backend(req, res, next);
backendWrapper.getHierarchy = () => backend.hierarchy;
module.exports = backendWrapper;
} else {
const backend = require(backendBuildPath).default;
const backendWrapper = (req, res, next) => backend(req, res, next);
backendWrapper.getHierarchy = () => backend.hierarchy;
module.exports = backendWrapper;
}