简体   繁体   中英

Symfony 3.4 - Webpack Encore and DOMPurify

I'm trying to integrate DOMPurify into my Symfony project, but I keep getting

DOMPurify isn't defined

In my browser's console. In my app.js I have:

import '../scss/custom.scss';
import $ from 'jquery';
import DOMPurify from 'dompurify';

global.$ = global.jQuery = $;

window.Popper = require('popper.js');
require('bootstrap');

And in my template:

{% block js %}
    {{ encore_entry_script_tags('app') }}
{% endblock %}

<script type="text/javascript">
    $('form[name=search_full]').submit(function(event) {
        let search = $('input[name=search]');
        search.value = DOMPurify.sanitize(search.value);
    });
</script>

I'm not sure how to correctly integrate it into my project. Any ideas?

对于其他有类似问题的人,解决方案似乎是在app.js文件中添加以下行:

window.DOMPurify = require('dompurify');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM