Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Rollup and external dependencies #21

Closed
chopfitzroy opened this issue Mar 28, 2019 · 5 comments
Closed

Rollup and external dependencies #21

chopfitzroy opened this issue Mar 28, 2019 · 5 comments
Labels
good first issue Good for newcomers Status: PR Welcome Type: Bug Something isn't working

Comments

@chopfitzroy
Copy link
Contributor

Using 0.2.1 as per #19 and it works brilliantly for rolling up .vue files.

Unfortunately I have now run into an issue where Rollup is trying to package up some external dependencies I am using (axios & is-object).

In an ideal world I would just like these to be installed into node_modules and the plugin use them from there.

#2357 on the official Rollup repo has some discussion surrounding this, it might be useful in helping to make a decision moving forward.

Not really sure what the best option is moving forward?

Cheers.

@chopfitzroy
Copy link
Contributor Author

Another option may be to resolve the modules directly: https://github.com/rollup/rollup-plugin-node-resolve

@kazupon kazupon added Type: Bug Something isn't working good first issue Good for newcomers Status: PR Welcome labels Mar 29, 2019
@chopfitzroy
Copy link
Contributor Author

chopfitzroy commented Mar 31, 2019

Looking to submit a PR, based on this article I believe we need to define external dependencies in rollup's external config (as opposed to globals).

Official documentation here, this example uses externals as well as the rollup-plugin-node-resolve plugin:

plugins: [resolve({
    // pass custom options to the resolve plugin
    customResolveOptions: {
        moduleDirectory: 'node_modules'
    }
})],
// indicate which modules should be treated as external
external: ['lodash']

If anyone know's anymore about this feel free to correct me before I start going down the wrong track.

@chopfitzroy
Copy link
Contributor Author

chopfitzroy commented Apr 1, 2019

Just noting down my progress here, more as a reference for myself than anything else.

I was able to build plugins by adding the following to the plugins array in buildinPlugins in lib/build/entry.js:

{
    // pass custom options to the resolve plugin
    customResolveOptions: {
        moduleDirectory: 'node_modules'
    }
}

I also added external: ['axios', 'is-object'] to generateConfig in lib/build/entry.js.

I did run into an issue where I was importing isObject like so:

import * as isObject from "is-object";

Instead I had to change it to:

import isObject from "is-object";

This appears to be related to #1267.

This builds with the following output:

Building for production mode as plugin ...
📦  dist/module-search.common.js 33.44kb
📦  dist/module-search.esm.js 33.27kb
No name was provided for external module 'axios' in output.globals – guessing 'axios'
No name was provided for external module 'is-object' in output.globals – guessing 'isObject'
📦  dist/module-search.umd.min.js 10.02kb (gzipped: 3.81kb)
No name was provided for external module 'axios' in output.globals – guessing 'axios'
No name was provided for external module 'is-object' in output.globals – guessing 'isObject'
📦  dist/module-search.umd.js 35.45kb

✅  Build complete. The dist directory is ready to be deployed.

As you can see rollup is guessing the externals currently (I am not sure why), but based on this issue I think we can read from the dependencies section of the package.json which may fix the issue as well as making the list dynamic (instead of hardcoded like it is currently).

EDIT

#1169 has more information on externals vs globals and helps to explain why rollup is guessing.

@kazupon
Copy link
Owner

kazupon commented Apr 30, 2019

commented at #22 (comment)

@kazupon
Copy link
Owner

kazupon commented May 14, 2019

I've released v0.3.0 :)

@kazupon kazupon closed this as completed May 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers Status: PR Welcome Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants