PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 26, 2022

[FIXED] How to set as external all node modules in rollup?

 November 26, 2022     module, node.js, rollup     No comments   

Issue

I want to have all modules imported from node_modules as external. What is the configuration for this?

I tried without success :

import path from "path";
import glob from "glob";
import multiEntry from "rollup-plugin-multi-entry";

export default {
    entry: "src/**/*.js",
    format: "cjs",
    plugins: [
        multiEntry()
    ],
    external: glob.sync("node_modules/**/*.js").map(file => path.resolve(file)),
    dest: "dist/bundle.js"
}];

or

import multiEntry from "rollup-plugin-multi-entry";

export default {
    entry: "src/**/*.js",
    format: "cjs",
    plugins: [
        multiEntry()
    ],
    external: id => id.indexOf("node_modules") !== -1,
    dest: "dist/bundle.js"
}];

Solution

You can accomplish that using package.json dependencies field:

const pkg = require('./package.json');

export default {
    // ...
    external : Object.keys(pkg.dependencies),
    // ...
}


Answered By - Isidrok
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing