Home / Snippets / How to Copy Styling and Scripts from node_modules in Laravel
How to Copy Styling and Scripts from node_modules in Laravel cover

How to Copy Styling and Scripts from node_modules in Laravel


2 years ago


When developing a Laravel project, sometimes you might need to copy the styling and scripts of an external library which is located inside the "node_modules". This is necessary in order to use the styling or scripts which by default can't be referenced when inside the node_modules.

Copy node_modules Style and Scripts using Laravel Mix

To copy the styles and scripts, you need to use Laravel Mix. A little bit of what Laravel Mix is:
Laravel Mix, a package developed by Laracasts creator Jeffrey Way, provides a fluent API for defining webpack build steps for your Laravel application using several common CSS and JavaScript pre-processors.
For this example let's imagine you want to copy Highlight.js styles from the "node_module" directory into your public directory. To do so you can write your code like below.
# webpack.mix.js
mix.copy('node_modules/highlight.js/styles/base16/apathy.css', 'public/css');
Once you have already define like so you can run the watch/dev/production command to copy the style/scripts.
npm run prod
If you are using yarn.
yarn prod
notion avatar

Ahmad Aziz

Week-end developer currently experimenting with web, mobile, and all things programming.






Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Post Tutorials

Learn trending tutorials for ReactJs, React Native, VueJS, NextJs, Laravel, Tailwind CSS, and Flutter development.
View Tutorials

Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your web projects
View Components

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this