Setting up Pintura Image Editor with NextJS
For a quick start use the NextJS example project as a guideline.
It includes a normal, modal, and overlay editor example as well as an integration of FilePond and Pintura Image Editor.
For the most part the NextJS installation process is the same as the React installation process, we only have to make a couple additional adjutments to the next.config.js
file.
Adjusting the next.config.js file
NextJS versions v13.2 and newer
We have to instruct NextJS to transpile the Pintura library, we can do so like this
module.exports = {
transpilePackages: ['@pqina/pintura', '@pqina/react-pintura'],
};
NextJS versions before v13.2
When using NextJS 13 we need to set the swcMinify
property to false
as it results in a client-side error, NextJS will then fallback to Terser. This is caused by a bug in SWC, the JavaScript compressor used by NextJS. This is fixed v13.2.
We have to install next-transpile-module
to transpile the Pintura modules.
npm i next-transpile-modules --save
Then we edit the config file as shown below.
const withTM = require('next-transpile-modules')([
'@pqina/pintura',
'@pqina/react-pintura',
]);
module.exports = withTM({
swcMinify: false,
});
Next steps
With the editor set up, we can continue to configure the editor to our liking by adjusting the available options exposed by the editor API