drop.chapril.org-firefoxsend/build/generate_asset_map.js

32 lines
851 B
JavaScript
Raw Normal View History

2018-03-06 01:29:09 +01:00
/*
This code is included by both the server and frontend via
common/assets.js
When included from the server the export will be the function.
When included from the frontend (via webpack) the export will
be an object mapping file names to hashed file names. Example:
"send_logo.svg": "send_logo.5fcfdf0e.svg"
*/
const fs = require('fs');
const path = require('path');
function kv(f) {
return `"${f}": require('../assets/${f}')`;
}
module.exports = function() {
const files = fs.readdirSync(path.join(__dirname, '..', 'assets'));
const code = `module.exports = {
"package.json": require('../package.json'),
2018-07-05 21:40:49 +02:00
"serviceWorker.js" : require('../app/serviceWorker.js'),
${files.map(kv).join(',\n')}
};`;
return {
code,
dependencies: files.map(f => require.resolve('../assets/' + f)),
2018-03-02 22:58:05 +01:00
cacheable: true
};
};