denisromanenko's avatar

What to do with CSS and JS from node_modules?

I'm newbie in frontend, so please don't blame me too much if my question is dumb.

When I want to use css and js from node_modules in my blade.php - how should I process it with Mix? Should I first copy all folder to assets and then prepate it? Or there is another way?

Before I only attach assets from CDN, so now its kinda hard for me to understand all things. Will be very grateful if you show me how to work with assets, installed to "node_modules"

0 likes
1 reply
MichalOravec's avatar

In your webpack.mix.js file you can add it from node_modules for example as

const mix = require('laravel-mix');

mix.sass('resources/sass/app.scss', 'public/css/app.min.css')
    .scripts([
        'node_modules/jquery/dist/jquery.js',
        'node_modules/datatables.net/js/jquery.dataTables.js',
        'node_modules/datatables.net-bs/js/dataTables.bootstrap.js',
    ], 'public/js/app.min.js');

if (mix.inProduction()) {
    mix.version();
}

Then tun this from console.

npm run dev

// or

npm run prod

Everything you can find in documentation: https://laravel.com/docs/7.x/mix

1 like

Please or to participate in this conversation.