Moving js (or/and css) to another bundle

I did a quick test, but ended up with javascript errors

I dont know if it is a good idea, but using 'require' in the template seems to work:

<script>
require([
  'jquery',
  '++plone++static/plone-datatables-compiled.min.js'
  ], function(Base) {
    'use strict';
    $('.sortable').DataTable( {
        rest of script here
      });
  });
</script>

PS: I have no idea why pat-moment also gives an error. This is a fresh (5.2) site

UPDATE: I only read the last answer, seems like others have used a similar approach.