So, recently I’ve had reason to dive into JS bundling and the like and I decided to try out rollup.js for this purpose because it seems simple and has some features I think seem good, like built in dead code elimination and so on.
When trying to use it together with phoenix.js
(shipped with Phoenix), rollup
tells me:
$ rollup -c
js/requestWait.js → ../priv/static/js/requestWait.js...
[!] Error: 'Socket' is not exported by ../../../deps/phoenix/priv/static/phoenix.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
js/requestWait.js (1:8)
1: import {Socket} from "phoenix";
^
My rollup.config.js
looks as follows (some of the config options have been changed in countless ways based on hours of googling and failing to fix this issue):
import commonjs from "rollup-plugin-commonjs";
import babel from "rollup-plugin-babel";
import nodeResolve from "rollup-plugin-node-resolve";
export default [
{
input: "js/requestWait.js",
output: {
file: "../priv/static/js/requestWait.js",
format: "iife",
sourceMap: "inline",
name: "requestWait",
},
plugins: [
nodeResolve({
jsnext: true,
main: true,
module: true,
browser: true,
preferBuiltins: false,
customResolveOptions: {
moduleDirectory: [
"node_modules",
"../../../deps/phoenix/priv/static",
"../../../deps/phoenix_html/priv/static",
]
}
}),
commonjs({
// I also tried adding `phoenix.js` here just to see if it would make any difference
include: /node_modules/,
sourceMap: false,
// This does nothing, neither with
// "../../../deps/phoenix/priv/static/phoenix.js"
// nor the way seen below
namedExports: {
"node_modules/phoenix/priv/static/phoenix.js": ["Socket"]
}
}),
babel({
exclude: ["/node_modules/**", "../../../deps/**"]
}),
]
}
];
Here is the .babelrc
I’m using (though I’m not sure it even gets to that step before complaining):
{
"presets": [
[
"env",
{
"modules": false
}
]
],
"plugins": ["external-helpers"]
}
So, does anyone who’s been using rollup with Phoenix (and also using Socket
from it, I suppose, though none of the other exports seem to work either) have any idea what to do in this situation?