Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
How to use webpack to join JS files?

I have to merge several files from my website with webpack, and for that I need to work with JS modules.

This is a child file.

export default () =>  {
    $('[data-direction]').on('click', switchFeatured)
    function switchFeatured (event) {
        const icon = $(event.currentTarget);
        if (icon.data().direction === 'right') {
            if (featuredCurrent < featuredTotal) {
                featuredCurrent++;
            }
        } else {
            if (featuredCurrent > 1) {
                featuredCurrent--;
            }
        }
        $('#featured-list').css('left', ( (featuredCurrent - 1) * -100) + '%');
    }
}

This is the main file.

window.$ = require ('jquery')

import Default from './pages/default'
import Home from './pages/home'

Default();
Home();

It's working this way, but is the way I export and use the imported modules correct? Got a better way?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If this work and you're happy with it then go for it.

But when using ES modules it's a little bit more idiomatic to import jquery whenever you use it:

// ./pages/default.js
import $ from 'jquery';

export default () => $(/* ... */);

// ./main.js
import Default from './pages/default'
import Home from './pages/home'

Default();
Home();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!