Closed Twipped closed 4 years ago
@Twipped: Thank you for sharing this... But do you have a config you can point me to which wasn't working--i.e., when you weren't using the alias plugin? Were you using the node-resolve and commonjs plugins? Also how you were invoking the config, e.g., the command line arguments used?
Here's the original config, minus any project specific bits.
const alias = require('@rollup/plugin-alias');
const commonjs = require('@rollup/plugin-commonjs');
const nodeResolve = require('@rollup/plugin-node-resolve');
const replace = require('@rollup/plugin-replace');
const babel = require('rollup-plugin-babel');
module.exports = exports = {
input: 'src/renderer.jsx',
output: [
{
dir: 'dist',
format: 'esm',
sourcemap: true,
entryFileNames: 'index.js',
},
],
manualChunks: { vendor: [
'lodash',
'preact',
'preact/compat/src/PureComponent.js',
'mobx',
'mobx-preact',
'prop-types',
'core-js',
'core-js-pure',
] },
plugins: [
alias({
entries: [
{ find: 'react', replacement: 'preact/compat' },
{ find: 'react-dom', replacement: 'preact/compat' },
{ find: 'uuid', replacement: require.resolve('uuid/dist/esm-browser') },
{ find: 'pure-component', replacement: require.resolve('preact/compat/src/PureComponent.js') },
],
}),
replace({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
'isProduction': process.env.NODE_ENV === 'production',
}),
babel({
exclude: 'node_modules/**',
}),
nodeResolve(),
commonjs({
include: 'node_modules/**',
sourceMap: false,
}),
],
watch: {
exclude: 'node_modules/**',
},
};
This is the babel config:
module.exports = exports = {
plugins: [
[ '@babel/plugin-proposal-object-rest-spread', { loose: true, useBuiltIns: true } ],
[ "@babel/plugin-proposal-decorators", { legacy: true } ],
[ "@babel/plugin-proposal-class-properties", { loose: true } ],
],
presets: [
[ "@babel/preset-env", {
useBuiltIns: "usage",
corejs: { version: 3, shippedProposals: true },
} ],
"preact",
],
};
And finally the browserslist config:
last 2 Chrome versions
last 2 Safari versions
last 2 Firefox versions
Thank you. I think given the complexity here, without a minimal reproducible repo including the input file, etc., it will take more effort than it may be worth to identify the problem. I don't know if it could be because Babel is run before the CommonJS or some other reason, but I haven't been able to replicate in a simpler config. So thank you for the information, but unless you want to go to the trouble of setting up a repo to replicate, I think we can leave it here with the info provided. Thanks!
Yeah, considering that you're clearly not having the problem with your own builds, I knew it had to be something specific in my setup. That's why I didn't suggest that it needed fixing. I just wanted to leave this here to give some people breadcrumbs incase they encounter the same issue.
Sure, understood. I tried tweaking it a little, like adding node_modules
to the CJS plugin, but that wasn't enough to trigger it. Thanks again!
I ran into a problem trying to use this on the web, because rollup just absolutely insisted that it had to require the
vm
module, even tho the code doesn't use it.The way I finally solved it was by creating an entry in
rollup-plugin-alias
to redirect thevm
module to use a localnull.js
module that just exports a default of null.Figured I would pass this along for anyone else who struggles with this after me.