Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple way to include node_modules in laravel 5.5

Tags:

laravel

How do you include /node_modules in a laravel 5.5 application, i referenced this https://laravel.com/docs/5.5/mix

i can do this

npm install angular-moment moment --save

and it will make a /node_modules directory, however laravel ignores it

lets say i want to do this

<script src="node_modules/moment/moment.js"></script>

it will not work, it will show an error

i currently have this in my webpack, what will be the best way to integrate it ?

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

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');
like image 564
BARNOWL Avatar asked Nov 25 '17 02:11

BARNOWL


1 Answers

Just include it in your app.js so it is complied in...

var moment = require('moment');

Then access it as moment... like

moment().format();
like image 162
Serge Avatar answered Nov 18 '22 09:11

Serge