2020-11-14 05:58:13 +08:00
|
|
|
config.middleware = config.middleware || [];
|
|
|
|
config.middleware.push('resource-loader');
|
|
|
|
|
|
|
|
function ResourceLoaderMiddleware() {
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
return function (request, response, next) {
|
|
|
|
try {
|
2020-12-24 04:48:53 +08:00
|
|
|
const content = fs.readFileSync(PROJECT_PATH + '/build/processedResources/js/test' + decodeURI(request.originalUrl));
|
2020-11-14 05:58:13 +08:00
|
|
|
response.writeHead(200);
|
|
|
|
response.end(content);
|
|
|
|
} catch (ignored) {
|
|
|
|
try {
|
2020-12-24 04:48:53 +08:00
|
|
|
const content = fs.readFileSync(PROJECT_PATH + '/build/processedResources/js/main' + decodeURI(request.originalUrl));
|
2020-11-14 05:58:13 +08:00
|
|
|
response.writeHead(200);
|
|
|
|
response.end(content);
|
|
|
|
} catch (ignored) {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
config.plugins.push({
|
|
|
|
'middleware:resource-loader': ['factory', ResourceLoaderMiddleware]
|
|
|
|
});
|