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

56
Views
Bundle Vue2 component library with webpack as separated files without broking tree-shaking

I am developing an Vue mixins library, I want to be able to import mixins in both these ways from this library:

// import type A
import { Theme } from 'awesome-lib/mixins'

and

// import type B
import Theme from 'awesome-lib/mixins/Theme'

for the type A of import, I have 1 entry in my webpack config file:

output: {
  path: path.join(__dirname, '/dist'),
  filename: '[name].js',
  libraryTarget: "umd",
  globalObject: 'this',
},
entry: {
  mixins: './src/mixins.js',

and for the type B of import, I create a separate entry for each file in mixins directory, like this:

entry: {
    // other entries
    ...glob.sync('./src/mixins/*.js').reduce((entries, file) => {
        const p = path.parse(file)
        entries[p.name] = {
            import: file,
            filename: 'mixins/' + p.base,
            dependOn: Dependencies[p.name],
        }
        return entries
    }, {}),

As it is visible this method has a downside, I need to set dependencies between entries manually for webpack or it will duplicate shared code in separated bundles. I have searched about bundling chunks based on file, but I could not find how? I have experimented with optimization.splitChunks with no luck. and a question: If I manage to config webpack to bundle by filename, can I load that file only in another package?

I was hoping with the right config I can achieve both outputs with only 1 entry and code splitting

about 4 years ago · Juan Pablo Isaza
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!