Skip to content

Instantly share code, notes, and snippets.

@brunos3d
Last active July 8, 2023 00:02
Show Gist options
  • Save brunos3d/745349c51983d23720a286e8e8e0e9b5 to your computer and use it in GitHub Desktop.
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
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