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

384

3 years ago

0 comments

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

Alaz

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

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this