Last active
April 2, 2025 19:15
-
-
Save brunos3d/745349c51983d23720a286e8e8e0e9b5 to your computer and use it in GitHub Desktop.
How to copy/use node_modules assets in Next.js public folder with copy-webpack-plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const CopyPlugin = require('copy-webpack-plugin'); | |
/** @type {import('next').NextConfig} */ | |
const nextConfig = { | |
reactStrictMode: true, | |
/** | |
* | |
* @param {import('webpack').Configuration} config | |
* @returns {import('webpack').Configuration} | |
*/ | |
webpack: (config) => { | |
config.plugins.push( | |
new CopyPlugin({ | |
patterns: [ | |
{ | |
from: 'node_modules/PACKAGE/PATH_TO_ASSETS', // e.g 'node_modules/leaflet/dist/images' | |
to: path.resolve(__dirname, 'public', 'PACKAGE', 'PATH_TO_ASSETS') // e.g 'public/leaflet/images' | |
}, | |
], | |
}), | |
) | |
return config | |
} | |
} | |
module.exports = nextConfig; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment