How do I use service workers in parcel? - babeljs

I have a service worker that comes from my js/index.js:
import '../scss/app.scss';
// Detect if service workers enabled
if ('serviceWorker' in navigator) {
try {
navigator.serviceWorker.register('../sw.js');
console.log('Service Worker Registered');
} catch (error) {
console.log('Service Worker Register Failed');
}
}
and my sw.js in my root directory:
const staticAssets = ['./', 'scss/app.scss', 'js/index.js'];
self.addEventListener('install', async (event) => {
const cache = await caches.open('min-static');
cache.addAll(staticAssets);
});
self.addEventListener('fetch', (event) => {
console.log('fetch');
});
Is babelized and put into the dist folder by parcel. When it's built and I go to localhost, I open chrome tools and go into the application tab. I go into the cache storage tab and:
What's going on? Why doesn't my website get nicely cached like in The PWA Tutorial?
Shouldn't it look like this:
?
Granted, I am running everything through babel, but why isn't it working?
Thanks in advance!

The error regeneratorRuntime is not defined happens because Babel (used by Parcel to transpile code) is generating a polyfill for ES6 generators in your build. To disable that (and fix your issue) you need to specify you don't want the generators to be transpiled.
Easy fix
An easy way to fix that would be to add the following lines to your package.json:
"browserslist": [
"since 2017-06"
],
This makes it so that your build will only attempt to support browser versions released since 2017-06, which do support ES6 generators and therefore do not need polyfills for that feature.
Alternatives
You might want to experiment with these values depending on your application's target audience, for example this should also work:
"browserslist": [
"last 3 and_chr versions",
"last 3 chrome versions",
"last 3 opera versions",
"last 3 ios_saf versions",
"last 3 safari versions"
]
More information
If you want to check which features are supported by each browser you can check here.
And if you want to check which options are valid for browserslint check here.
There is also more discussion available regarding your specific issue here.

I am pretty new to Parcel and I am facing the same issue.
After spending a few hours of searching online and I guess it may have something to do with this issue parcel-bundler/parcel #301: 🙋 PWA support
Although, there are 2 plugins and 1 discussion which vows to address this issue.
For the time being, I don't see any perfect solution.
If you happen to find some new discovery, please let us know.

Related

nuxt 3 : generate and host a small pwa

I'm testing Nuxt 3 (RC for now), and really love it.
I made a very small front-end application ( no backend, 3 pages, a complex form with some formulas to display some results ).
it works nice locally, there is nothing related to backend, so
I obviously could used only Vue,
but for testing purpose and to go further, I would like to generate a PWA, host it on a dev server ( in a subfolder ) and try to install it on my phone.
It seems nuxt-pwa is not still compatible with nuxt 3,
according to this issue, I've installed kevinmarrec/nuxt-pwa-module,
It works partially ( well.. favion and icons is generated locally )
but I don't know how to configure nuxt.config.js:
the router didn't match the subfolder,
no styles or reactivity is working, I got only my html displayed
I don't even know which command to use : npm run build or generate
I've looked a couple of hours, unsuccesfully, so is there someone knowing some good resources explaining how to turn a Nuxt 3 app into PWA and solve my silly problems
thanks :)
Hey sorry for the late reply, but the API is similar to that of nuxt/pwa meaning configuration from nuxt/pwa will most likely work with the module. To confirm try adding the following pwa config to your nuxt.config.js and check if it works
meta: {
name: 'Demo Site',
description: "Some juicy description",
theme_color: "#dddddd",
},
Note: the name property changes the title of the page. The description adds a meta description tag and the theme_color adds a meta theme-color tag
You can find out more from https://pwa.nuxtjs.org/meta
Any of the commands build or generate will work, but preferably build

What are Visual Studio Code experiments?

Today I was surprised to find an "Enable Experiments" option under VSCode's Workbench settings, turned on by default.
The setting's description is "Fetches experiments to run from a Microsoft online service" which seems rather vague to me. I tried googling this but didn't find any clear answers.
So, does anybody know what those "experiments" are and if it would probably be better to turn this off?
This is one of the case where using open-source software is a good idea. Because the source code of visual studio code is published in https://github.com/Microsoft/vscode. We could try to search in where the code would be used.
First, we could try to search the string Enable Experiments. And see, to which action the option is tied to. From there, I see that, the file src/vs/workbench/contrib/experiments/node/experimentService.ts is using it. Specifically, when trying to load an experiment in line 173
if (!product.experimentsUrl || this.configurationService.getValue('workbench.enableExperiments') === false) {
We see that, the code would check for "experiment URL". this could be seen in product.json which #Joey mentioned in the comment. In my case, the text looks like this.
"experimentsUrl": "https://az764295.vo.msecnd.net/experiments/vscode-experiments.json",
From there, we could see the content of the JSON file by making a GET request to that URL. And, it returns this (at least, at the time I make the request)
{
"experiments": [
{
"id": "cdias.searchForAzure",
"enabled": true,
"action": {
"type": "ExtensionSearchResults",
"properties": {
"searchText": "azure",
"preferredResults": [
"ms-vscode.vscode-node-azure-pack",
"ms-azuretools.vscode-azureappservice",
"ms-azuretools.vscode-azurestorage",
"ms-azuretools.vscode-cosmosdb"
]
}
}
}
]
}
Based on the response, I could see that, it try to alter my search result if I search using "azure" key word. Which I tried, and the search result shows the 4 items there on top of the result search.
As to whether to disable it or not. On safe side (if you don't want for it to alter your experience using vscode) I think you would want to disable it. But, I don't think microsoft would do something crazy.
I just noticed this one and was curious about it as well. A search through the VS Code release notes finds one reference to it in July 2018. workbench.enableExperiments is listed as one of the settings for VS Code's "Offline mode": https://code.visualstudio.com/updates/v1_26#_offline-mode
The description of offline mode suggests that this settings is for "A/B experiments":
To support this offline mode, we have added new settings to turn off features such as automatic extension update checking, querying settings for A/B experiments, and fetching of online data for auto-completions.
As mentioned by others, the source code for VS Code shows this setting being used in experimentService.ts: https://github.com/microsoft/vscode/blob/93bb67d7efb669b4d1a7e40cd299bfefe5e85574/src/vs/workbench/contrib/experiments/common/experimentService.ts
If you look at the code of experimentService.ts, the stuff it's fetching seems to be related to extension recommendations, notifications about new features, and similar things. So it looks like the experiment service is for fetching data to do A/B testing of feature and extension recommendations to users.

What is the developer flow for ember-engines?

I am just beginning to look into Ember.js engines. One thing that stands out is that for every change I make in the engine code I need to re-install it into the host application. There is no live reload, rebuild or any of this.
Is there a way to smooth out this flow as it would slow down development considerably.
The trick is to set isDevelopingAddon like so in the index.js file for the addon and use NPM link to get it into the main application node_packages folder - you will then get live reload, etc-:
// Addon index.js
isDevelopingAddon: function() {
return true;
}
To add to this I found an interesting article here: Ember and Yarn Workspaces

Provide REST API from Ionic App

is it possible to provide a REST API from an Ionic App?
I tried to install express, to receive REST calls, but no luck so far.
Background is, that I want to call from one Ionic2 app a method of another Ionic2 app.
I looked hours around but couldn't find a way to do such thing. I know this is not the common way, but it's necessary for my case, because it should replace push notifications in a quite dirty way (due to missing dev accounts and it's just for demonstration purpose)
Have you looked into the Ionic Native httpd plugin? This may provide what you are looking for with a few tweaks
Usage example straight from their docs:
import { Httpd, HttpdOptions } from '#ionic-native/httpd';
constructor(private httpd: Httpd) { }
...
let options: HttpdOptions = {
www_root: 'httpd_root', // relative path to app's www directory
port: 80,
localhost_only: false
};
this.httpd.startServer(options).subscribe((data) => {
console.log('Server is live');
});

Plone 4.2 TinyMCE jQuery UI Dialog

I am currently writing a replacement for the plone dialog infrastructure. Mostly for personal use and fun, but available on github as collective.js.jqueryuidialog.
Currently I'm struggling to manage the initialization for the tinyMCE editor in the dialogs.
I tried to get the missing scripts with getScript, but then I get stuck. I googled and found some init hooks, like this one
$(document).bind('loadInsideOverlay', function() {
$('textarea.mce_editable').each(function() {
var config = new TinyMCEConfig($(this).attr('id'));
config.init();
});
});
but none worked.
Any ideas or recommendations to read further?
Update
I updated Products.TinyMCE to version 1.3.3 and proceeded through the upgrade steps in the ZMI. All other functionality is still working (Yeehaa).
I realized, that the call seems to have changed, since all pages with a tinyMCE on it, now issue a get command to a view named tiny_mce_gzp.js that seems to deliver the actual configured editor from the portal.
Actually I am digging the source to find that call and copy it's behavior.