小编Ren*_*jus的帖子

notificationclick 事件服务工作者


我正在与服务人员合作在我的用户之间显示通知。在我的代码中我包含notificationclick事件。通过这次活动,我试图处理两个案例。第一种情况,如果在我的浏览器中打开了我的网站页面,请不要打开它,而是关注它。第二种情况,如果我的浏览器没有显示我的网站,请打开它并关注它。但我还没有成功...

这是我当前的代码:

self.addEventListener('notificationclick', function (e) {
    console.log('notification was clicked')
    var notification = e.notification;
    var action = e.action;

    if (action === 'close') {
        notification.close();
    } else {
        // This looks to see if the current is already open and
        // focuses if it is
        e.waitUntil(
            self.clients.matchAll().then(function(clientList) {
                console.log(clientList)
                if (clientList.length > 0) {
                    console.log(clientList[0])
                    return clientList[0].focus();
                }
                return self.clients.openWindow('/');
            })
       );
   };
});
Run Code Online (Sandbox Code Playgroud)

javascript push-notification service-worker workbox

3
推荐指数
1
解决办法
2659
查看次数

webpack缩小HtmlWebpackPlugin


我正在尝试使用带HtmlWebpackPlugin插件的Webpack缩小我的html文件。我设法将index.html文件制作到dist加载程序中,但是在缩小文件时遇到了一些麻烦。

dist/
node_modules/
src/
   ejs/
   js/
   css/
server.js
webpack.config.js
package.js
Run Code Online (Sandbox Code Playgroud)

webpack.config.js:

var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {

    entry: './src/js/index.js',

    devtool: 'source-map',

    output: {
        publicPath: '/dist/'
    },

    module: {
        rules: [
            {
                test: /\.ejs$/,
                use: ['ejs-loader']
            },
            {
                test: /\.css$/,
                use: ExtractTextPlugin.extract({
                    use: [{
                            loader: 'css-loader',
                            options: {
                                url: false,
                                minimize: true,
                                sourceMap: true
                            }
                        }]
                })
            }
        ]
    },

    plugins: [
        new HtmlWebpackPlugin({
            template: './src/ejs/index.ejs',
            minify: true
        }),
        new …
Run Code Online (Sandbox Code Playgroud)

javascript minify webpack html-webpack-plugin

2
推荐指数
1
解决办法
3564
查看次数