在 laravel 5.5 中包含 node_modules 的简单方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47481995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:00:30  来源:igfitidea点击:

simple way to include node_modules in laravel 5.5

laravel

提问by BARNOWL

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

你如何在 laravel 5.5 应用程序中包含 /node_modules,我引用了这个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

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

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 ?

我目前在我的 webpack 中有这个,集成它的最佳方法是什么?

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

回答by Serge

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

只需将它包含在您的 app.js 中,以便符合...

var moment = require('moment');

Then access it as moment... like

然后作为时刻访问它......就像

moment().format();