S
S
s-morello2019-08-27 06:50:49
JavaScript
s-morello, 2019-08-27 06:50:49

How to import the contents of a js file and not a link to it?

How to connect scripts that are in node_modules so that in the final file there is not a link to the file, but the content in the file?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mitya ToDaSyo, 2019-08-27
@dimastik1986

via ajax...
why is this method bad?

function include(filename) {	
  var js = document.createElement('script');
  js.setAttribute('src', filename);
  document.getElementsByTagName('HEAD')[0].appendChild(js);
  var cur_file = {};
  cur_file[window.location.href] = 1;
  if (!window.js_file)
    window.js_file = {};
  if (!window.js_file.includes)
    window.js_file.includes = cur_file;
  if (!window.js_file.includes[filename]) {
    window.js_file.includes[filename] = 1;
  } else {
    window.js_file.includes[filename]++;
  }
  return window.js_file.includes[filename];
}

(function () {
  var JSlist = [];
  JSlist.push('/js/jquery-easing.js');
  JSlist.push('/js/jquery.maskedinput.js');
        ...
  JSlist.forEach(function (URL) {
    include(URL);
  });
}());

A
Anton Khmyrov, 2019-08-27
@vivcogit

you need to add browserify to the build tasks before uglify

V
Vladimir, 2019-08-27
@Casufi

https://rollupjs.org/guide/en/
https://parceljs.org/
https://webpack.js.org/
Webpack can be used both without gallp and with gallp, the rest seem to be the same, but I haven't tried

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question