laravel 5.5中包含node_modules的简单方法 [英] simple way to include node_modules in laravel 5.5

查看:682
本文介绍了laravel 5.5中包含node_modules的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何在laravel 5.5应用程序中包含/node_modules,我引用了 https://laravel.com /docs/5.5/mix

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

我可以做到

npm install angular-moment moment --save

它将创建一个/node_modules目录,但是laravel会忽略它

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

让我说我想做

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

它不起作用,将显示错误

it will not work, it will show an error

我目前在我的webpack中有此功能,将其集成的最佳方法是什么?

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');

推荐答案

只需将其包含在您的app.js中,以便在...中进行编译

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

var moment = require('moment');

然后即刻访问它,就像

moment().format();

这篇关于laravel 5.5中包含node_modules的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆