is nextjs 12 and 13 version supports the subresource integrity for CDN javascripts?

705 Views Asked by At

We have Next JS 12 version in our application, I have searched about SRI implementation for Next JS 12 version,then found this offical Next JS GitHub discussion link. I have tried with SRI configuration as per discussion in GitHub but no fruitful results.

in next.config.js file

const withOffline = require('next-offline');
const withPlugins = require('next-compose-plugins');
const CompressionPlugin = require('compression-webpack-plugin');
const SriPlugin = require('webpack-subresource-integrity');
let nextConfig = {};

const customConfig = {
  webpack: (config, { isServer, dev }) => {
    config.output.crossOriginLoading = 'anonymous';
    config.plugins.push(
      new SriPlugin({
        hashFuncNames: ['sha256', 'sha384'],
        enabled: true,
      })
    );

    return config;
  },
};

nextConfig = {
  ...customConfig,
};

module.exports = withPlugins([[withOffline, { scope: '/' }], [{ compress: true }]], nextConfig);

but am getting the sriplugin is not a constructor. please advice me further what I made mistakes in configuration. Thanks in advance.

I have tried with webpack-subresource-integrity plugin configuration in Next JS 12 but getting error as sriplugin is not a constructor.

I am expecting that to resolve this SRI configuration issue and know about that Next JS 12 and 13 supports the SRI.

1

There are 1 best solutions below

0
Guillaume Lamanda On

According to the documentation of the package, you should import it like that :

import { SubresourceIntegrityPlugin } from "webpack-subresource-integrity";
// or: const { SubresourceIntegrityPlugin } = require('webpack-subresource-integrity');