Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/playground/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
</style>
</head>
<body>
<% if (htmlWebpackPlugin.options.pwa) { %>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
Expand All @@ -52,5 +53,25 @@
console.log('Service Worker is not supported by browser.');
}
</script>
<% } else { %>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.getRegistration('./service-worker.js').then(function (registration) {
if (registration) {
console.log('found PWA worker registration', registration.scope);
registration.unregister().then(function (result) {
console.log('PWA worker unregister', result);
});
} else {
console.log('no PWA worker registration');
}
});
});
} else {
console.log('Service Worker is not supported by browser.');
}
</script>
<% } %>
</body>
</html>
15 changes: 10 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,24 @@ const buildConfig = baseConfig.clone()
chunks: ['gui'],
template: 'src/playground/index.ejs',
title: 'Smalruby',
originTrials: JSON.parse(fs.readFileSync(path.resolve(__dirname, 'origin-trials.json')))
originTrials: JSON.parse(fs.readFileSync('origin-trials.json')),
pwa: process.env.NODE_ENV === 'production'
}))
.addPlugin(new HtmlWebpackPlugin({
chunks: ['gui'],
template: 'src/playground/index.ejs',
filename: 'ja.html',
title: 'スモウルビー',
originTrials: JSON.parse(fs.readFileSync(path.resolve(__dirname, 'origin-trials.json')))
originTrials: JSON.parse(fs.readFileSync('origin-trials.json')),
pwa: process.env.NODE_ENV === 'production'
}))
.addPlugin(new HtmlWebpackPlugin({
chunks: ['player'],
filename: 'player.html',
template: 'src/playground/index.ejs',
title: 'Smalruby: Player Example',
originTrials: JSON.parse(fs.readFileSync(path.resolve(__dirname, 'origin-trials.json')))
originTrials: JSON.parse(fs.readFileSync('origin-trials.json')),
pwa: process.env.NODE_ENV === 'production'
}))
.addPlugin(new CopyWebpackPlugin({
patterns: [
Expand All @@ -145,7 +148,9 @@ const buildConfig = baseConfig.clone()
context: 'src/examples'
}
]
}))
}));

const buildWithPwaConfig = buildConfig.clone()
.addPlugin(
new WorkboxPlugin.GenerateSW({
disableDevLogs: !process.env.DEBUG,
Expand Down Expand Up @@ -188,5 +193,5 @@ const buildConfig = baseConfig.clone()
const buildDist = process.env.NODE_ENV === 'production' || process.env.BUILD_MODE === 'dist';

module.exports = buildDist ?
[buildConfig.get(), distConfig.get()] :
[buildWithPwaConfig.get(), distConfig.get()] :
buildConfig.get();