Загрузить скрипт в проблеме веб-работника

У меня проблема с импортом скрипта в веб-рабочий. Я пытаюсь импортировать highlight.pack.js, но он выдает сообщение об ошибке ниже. Любое предложение было бы здорово!

Не удалось выполнить "importScripts" на "WorkerGlobalScope": URL-адрес "/Scripts/highlighter/highlight.pack.js" недействителен.

AngularJS: 1.4.7

Webpack: 4

Вот мой highlight.worker.js:

self.onmessage = function (e) {
    importScripts('/Scripts/highlighter/highlight.pack.js');
    for (var i = 0; i < e.data.textBlocksToSend.length ; i++) {
        e.data.textBlocksToSend[i].textcontent = self.hljs.highlightAuto(e.data.textBlocksToSend[i].textcontent);

    }
    self.postMessage({ textBlocksToReturn: e.data.textBlocksToSend });
}

Вот моя директива:

var Worker = require('./highlight.worker.js');

module.exports = function (app) {
    app.directive("syntaxHighlighter", ["highlightService", function (highlightService) {
        return {
            scope: {
                htmlContent: "="
            },
            link: function ($scope, $element, $attrs, controller) {

                $scope.$watch('htmlContent', function () {

                    .
                    .
                    .
                    .
                    .
                    .

                    if (window["Worker"]) {
                        var worker = new Worker();
                        worker.onmessage = function (event) {
                            for (var i = 0; i < elements.length; i++) {
                                $(elements[i]).html(event.data.textBlocksToReturn[i].textcontent.value);
                            }
                        }
                        worker.postMessage({ textBlocksToSend: textBlocks });
                    }
                });
            }
        };
    }]);
};

0 ответов

Другие вопросы по тегам