The bootstrap.js file of laravel5.3 has the following lines:
window._ = require('lodash');
window.$ = window.jQuery = require('jquery');
require('bootstrap');
window.Vue = require('vue');
require('vue-resource');
Question:
1, window._
and window.$ = window.jQuery
, window.Vue
means What's the meaning? Do I need to write this line first every time I introduce a package?
2. Does require() introduce the entire package or just the js file? It cannot be seen from the require('') brackets that the folder name and js file name are the same.
Laravel 5.3’s app.js/boostrap.js cannot be accessed through
<script src='...'></script>
Because it is based on
nodeJS + gulp + webpack
的一套东西,打开根目录下的
gulpfile.js
可以看到elixir的函数
, this function is used to open js and cssHow to use:
Install nodejs
Open command line
cd /your/root/dir/
npm install -g gulp
(The speed is very slow, you can search and install: cnpm)npm install
gulp
This will be in your
public/css public/js
下生成app.js app.css
This is what you can
<script src=""></script>
Your question:
window.$ = window.jQuery = require('jquery');
指将jquery
导入进来,并赋值给$
Variablesrequire
是nodeJS
的语法,读取的是node_modules/
下的某个文件夹的index.js
(具体要看package.json
pointing)Open
node_modules/
and you can see a lot of librariesOpen
package.json
and you can see the required node libraryOpen
gulpfile.js
可以添加需要webpack/sass/less
’s file