B
B
BMaks_N12019-07-07 00:05:20
JavaScript
BMaks_N1, 2019-07-07 00:05:20

Combining JS files, what's the best way?

The bottom line is, there is a JS file, it has a function, and another function that calls the first one, you need to divide this file into 2, one function in one, another in the other, all this is then run through webpack,
I tried it through include ( " ./qwerty.js"), does not work
If I specify several files in the Entry in webpack, then functions from different files are not visible.
I tried import {qwerty} from "./qwerty.js" also does not work, how to treat it?)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Sokolov, 2019-07-07
@sergiks

Using globals goes against the whole idea of ​​webpack, but if it's such a heavy legacy,
see Global Exports - use exports-loader.
Try adding to webpack.config.js:

module: {
      rules: [
       {
         test: require.resolve('qwerty.js'),
         use: 'exports-loader?qwerty'
       }

and in the main code
import { qwerty } from './qwerty.js';

K
Konstantin Kitmanov, 2019-07-07
@k12th

If import {qwerty} from "./qwerty.js"it doesn't work, then you forgot export function qwerty() {}.

R
Robur, 2019-07-08
@Robur

The quickest way to fix it is to understand modules and how import/export works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question