注意:本節命令均需要在項目根目錄下運行。
[TOC]
## 編譯
>[info] 所有編譯后的資源文件都被存放在 `public` 文件夾中。
### 開發模式
>[warning] 生成的文件未被壓縮,便于開發調試:
~~~bash
$ npm run dev
~~~
或
~~~bash
$ npm run developmennt
~~~
### 生產模式
>[success] 生成的文件自動經過壓縮,便于線上加載:
~~~bash
$ npm run prod
~~~
或
~~~bash
$ npm run production
~~~
## 監控
>[info] 可在開發時一直運行,Webpack 檢測到文件更改時將自動重新編譯資源:
~~~bash
npm run watch
~~~
在某些環境中,當文件更改時,Webpack 不會更新。
如果系統出現這種情況,請考慮使用 `watch-poll` 命令:
~~~bash
$ npm run watch-poll
~~~
## 可能出現的報錯
### Module build failed: `node-sass`
>[danger] 報錯內容:
~~~bash
ERROR Failed to compile with 2 errors
error in ./resources/assets/sass/app.scss
Module build failed: Error: ENOENT: no such file or directory, scandir '/home/vagrant/Code/Laravel/node_modules/node-sass/vendor'
·
·
·
error in ./resources/assets/sass/app.scss
Module build failed: ModuleBuildError: Module build failed: Error: ENOENT: no such file or directory, scandir '/home/vagrant/Code/Laravel/node_modules/node-sass/vendor'
~~~
>[warning] 報錯原因:
> 打開 `~node_modules/node-sass/vendor` 文件夾下為空,缺少 `linux-x64-48/binding.node` 文件。
>[success] 解決方法:
> 執行以下命令,更改包內容后進行重建
~~~bash
$ npm rebuild node-sass --no-bin-links
~~~
>[info] 成功后顯示:
~~~bash
Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.3/linux-x64-48_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.3/linux-x64-48_binding.node":
ETIMEDOUT
Timed out attemping to establish a remote connection
·
·
·
gyp info ok
Installed to /home/vagrant/Code/Laravel/node_modules/node-sass/vendor/linux-x64-48/binding.node
node-sass@4.5.3 /home/vagrant/Code/Laravel/node_modules/node-sass
~~~
### Module build failed: `optipng-bin`
>[danger] 報錯內容:
~~~bash
ERROR Failed to compile with 2 errors
error in ./resources/assets/semantic/dist/themes/default/assets/images/flags.png
Module build failed: Error: spawn /home/vagrant/Code/Laravel/node_modules/optipng-bin/vendor/optipng ENOENT
·
·
·
error in ./resources/assets/sass/app.scss
Module build failed: ModuleBuildError: Module build failed: Error: spawn /home/vagrant/Code/Laravel/node_modules/optipng-bin/vendor/optipng ENOENT
~~~
>[warning] 報錯原因:
> 打開 `~node_modules/optipng-bin` 文件夾下缺少 `vendor/optipng` 文件。
>[success] 解決方法:
> 執行以下命令,更改包內容后進行重建
~~~bash
$ npm rebuild optipng-bin --no-bin-links
~~~
>[info] 成功后顯示:
~~~bash
·
·
·
? optipng pre-build test passed successfully
optipng-bin@3.1.4 /home/vagrant/Code/Laravel/node_modules/optipng-bin
~~~
### Cannot find module 'xxxxx'
>[danger] 報錯內容舉例:
~~~bash
module.js:471
throw err;
^
Error: Cannot find module 'crypt'
~~~
>[warning] 報錯原因:
> 因為網絡或者其他原因,導致某個擴張包沒有正常安裝上。
> `~node_modules` 目錄下沒有 `crypt` 文件夾。
>[success] 解決方法:
缺少什么包就添加什么包。
當然也可以 [清空所有擴展包,然后重新安裝一遍](frontend/install-packages.md)。
- 日常命令
- 第一章 開發環境部署
- 第一節 安裝 VirtualBox
- 第二節 安裝 Vagrant
- 第三節 安裝 Git for Windows
- 命令行提示符的寫作約定
- Git Bash 使用技巧
- 第四節 安裝和配置 Homestead
- 第五節 啟動 Homestead 虛擬機
- 第六節 創建 Laravel 應用
- 第七節 使用 Git 進行版本控制
- 總結 本章命令概覽
- 第二章 前端工作流
- 第一節 Yarn 安裝前端擴展包
- 第二節 Laravel Mix 前端資源編譯
- (1)配置 webpack.mix.js 指定 Mix 任務
- (2)修改 resources/assets 前端資源文件
- (3)運行 Mix 任務編譯和監控代碼
- 總結 本章命令概覽
- 第三章 數據庫
- 第一節 Config 數據庫配置信息
- 第二節 Migrations 數據庫遷移文件
- 第三節 Schema 數據庫結構生成器
- (1) 數據表操作
- (2) 字段操作
- (3) 索引操作
- 第四節 Seeding 數據填充
- 第五節 DB 數據庫查詢構建器
- (1)獲取結果集