I created simple app used angular elements and http node server. To optimize bundle size i just convert the resulting js file to gz format with current command:
"postbuild": "cat dist/cs6-user-widget/{runtime,polyfills,polyfills-es5,scripts,main}.js | gzip > webcomponent/user-widget.js.gz" The file is created correctly, but i cannot serve this type of content with my node server:
const http = require('http'); const fs = require('fs'); const hostname = 'localhost'; const port = 4202; http.createServer((request, response) => { var contentType = 'text/html'; var filePath = './' + request.url; fs.readFile(filePath, function(error, content) { if (error) { fs.readFile('./index.html', function(error, content) { response.writeHead(200, { 'content-encoding': 'gzip', 'Content-Type': contentType }); return response.end(content, 'utf-8'); }); } else { response.writeHead(200, { 'content-encoding': 'gzip', 'Content-Type': contentType }); return response.end(content, 'utf-8'); } }); }); Can You help me to correctly implement node part?