Next.js Discord

Discord Forum

Webpack minification creates unusable code

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
Here's the scenario: I have an external file that is not being used by any of my other components which I want nextjs to bundle with the final output. I am building an extension using nextjs and the external file is just a content script which I want to run. Problem is that once the bundling is done by web pack that content script doesn't work.I know this because I tested the file with regular code and it worked (logged a message).

Here is my webpack config for anybody interested:

/** @type {import('next').NextConfig} */
 const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
})
const nextConfig = withBundleAnalyzer({
  reactStrictMode: true,
  swcMinify: true,
  
  images: {
    unoptimized: true,
  },
  webpack: (config,options) => {
        return {
            ...config,
            entry: async()=>{
              const con =await config.entry()
             
           
              return {...con, 'modal':'./content-script/content-main.js' }
              
            },
        
    }
  
  },


   
 
});

module.exports = nextConfig;

0 Replies