The npm package problem is introduced in the bootstrap.js file of laravel5.3
PHP中文网
PHP中文网 2017-05-16 16:49:44
0
1
387

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.

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
伊谢尔伦

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 css

How 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导入进来,并赋值给$Variables

  • requirenodeJS的语法,读取的是 node_modules/下的某个文件夹的index.js (具体要看package.json pointing)

  • Open node_modules/ and you can see a lot of libraries

  • Openpackage.json and you can see the required node library

  • Open gulpfile.js 可以添加需要webpack/sass/less’s file

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template