I'm making an update answer to this question, as some ProseMirror and Rollup bundles have been upgraded since the last answers were made.
Here are the steps that worked for me after almost 3 days of searching through the web.
In the root directory of you app, initialize node_modules and package.json :
npm init
Install ProseMirror and Rollup basic bundles that we will need for the main.js file and the rollup.config.js file :
npm install prosemirror-view prosemirror-model prosemirror-state prosemirror-transform prosemirror-schema-basic @rollup/plugin-commonjs @rollup/plugin-node-resolve @rollup/plugin-replace @rollup/plugin-terser --save-dev
In your package.json, add those lines after the description :
"main": "dist/prosemirror-bundle.min.js",
"module": "public/js/main.js",
"type": "module",
Create a file named rollup.config.js in the root directory of your application (where your package.json is located), and fill it with those lines :
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
export default {
input: 'public/js/main.js', // Entry point for the bundle
output: {
file: 'dist/prosemirror-bundle.min.js', // Output file path and name
format: 'umd', // Format of the output bundle (Universal Module Definition)
name: 'ProseMirror' // Name of the exported global variable
},
plugins: [
resolve({
browser: true, // Resolve modules for browser environment
preferBuiltins: false // Do not prefer built-in modules over local modules
}),
commonjs(), // Convert CommonJS modules to ES6
replace({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'), // Replace NODE_ENV variable with 'development' (or current environment)
preventAssignment: true // Prevent replacement of variable assignment
}),
(process.env.NODE_ENV === 'production' && terser()) // If in production environment, minify the code
]
};
Create the main.js file (mine is in public/js as I mentioned in the package.json AND rollup.config.js) and write down those lines :
import { EditorState } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
import { schema } from 'prosemirror-schema-basic';
window.addEventListener('DOMContentLoaded', (event) => {
console.log("2");
const editorNode = document.getElementById('mad_interactive_editor');
const state = EditorState.create({
schema,
});
const view = new EditorView(editorNode, {
state,
});
});
Create an html file and add a div inside :
<div id="mad_interactive_editor"></div>
Update your package.json with the dependencies :
npm install
Build your code using rollup config file with this command :
rollup -c
You can either add —watch in the end of this command to keep watching for changes in your input file (main.js) while your are coding like this :
rollup -c —watch
If you are not in a dev environment anymore, run the following command instead, it will minify your code :
NODE_ENV=production rollup -c rollup.config.js
And you should have your ProseMirror implemented in your html page.
I hope this can help someone.