国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
What is laravel mix? What is the use?
Default What is laravel mix used for? and folder structure
Main Mix Methods
Mix.manifest.json and cache clearing
mix() Help
代碼拆分
自定義 Webpack 配置
順便一提
默認(rèn)依賴關(guān)系
小結(jié)
Home PHP Framework Laravel What is laravel mix used for?

What is laravel mix used for?

Jan 14, 2023 am 10:41 AM
php laravel

laravel mix is ??used to manage front-end tasks. It is a front-end task automation management tool that can use the workflow mode to execute the specified tasks in sequence; Mix provides a simple and smooth API, allowing developers to Define Webpack compilation tasks for Laravel applications to easily manage front-end resources.

What is laravel mix used for?

The operating environment of this tutorial: Windows 7 system, Laravel 6 version, DELL G3 computer.

What is laravel mix? What is the use?

Laravel Mix is ??a front-end task automation management tool that uses the workflow model to execute specified tasks in sequence. Mix provides a simple and smooth API that allows you to define Webpack compilation tasks for your Laravel applications. Mix supports many common CSS and JavaScript preprocessors, and you can easily manage front-end resources with simple calls.

Default What is laravel mix used for? and folder structure

The default Sass What is laravel mix used for? is in resources/assets/sass/app.scss (the content of the What is laravel mix used for? is completely The same), and the default JS What is laravel mix used for? is in resources/assets/js/app.js (because the What is laravel mix used for? is exactly the same, so if you want to learn more about the infrastructure of Vue in 5.3, you can check Matt Stauffer wrote the front-end structure of 5.3 this post).

If you dig into the bootstrap What is laravel mix used for? referenced in app.js ( resources/assets/js/bootstrap.js ), you will see that we use Axios instead of Vue-Resource to set up X-CSRF-TOKEN (Vue-Resource will no longer work after 2016).

If you run npm run dev on the Mix project, you can see:

What is laravel mix used for?

By default, we generate The location of the What is laravel mix used for?s is the same as Elixir: public/css/app.css and public/js/app.js.

Main Mix Methods

As you can see, you can easily use Mix with Sass and JS. Sass, obviously, runs a Sass What is laravel mix used for? and outputs it as CSS. Use JS methods to support ECMAScript 2015 syntax, compile .vue What is laravel mix used for?s, minify code for production, and perform other processing of JavaScript What is laravel mix used for?s.

You can also use the .less method to compile Less into CSS:

mix.less('resources/assets/less/app.less',?'public/css');

Use the combine method to combine What is laravel mix used for?s in Together:

mix.combine([
????'public/css/vendor/jquery-ui-one-thing.css',
????'public/css/vendor/jquery-ui-another-thing.css'
],?'public/css/vendor.css');

Copy What is laravel mix used for?s or directories with copy:

mix.copy('node_modules/jquery-ui/some-theme-thing.css',?'public/css/some-jquery-ui-theme-thing.css');
mix.copy('node_modules/jquery-ui/css',?'public/css/jquery-ui');

Unlike Elixir, Source Maps are turned off by default and can be used in webpack.mix Call the following method in .js to enable it:

mix.sourceMaps();

By default, Mix will notify you of the compilation results in the form of system notifications. If you do not want them to run, you can use disableNotifications() Method disabled.

Mix.manifest.json and cache clearing

Those familiar with Elixir may notice that the output image above is a little different from Elixir: Mix is ??generating an out-of-the-box manifest What is laravel mix used for? public/mix-manifest.json. Of course, Elixir also generates the manifest What is laravel mix used for?: public/build/rev-manifest.json, and unlike Mix's direct production, it only generates it when it determines that the cache clearing (versioning) feature is enabled.

These manifest What is laravel mix used for?s are used to map front-end What is laravel mix used for?s to versioned copies of front-end What is laravel mix used for?s, for example: /js/app.js and /js/app-86ff5d31a2. Mapping between js. With this What is laravel mix used for?, you can use a simple reference in HTLM to point to the referenced versioned What is laravel mix used for?. For example <script src="%7B%7B%20mix('js/app.js')%20%7D%7D"></script> .

Unlike Elixir, even if you don't use cache clearing, Mix will generate this What is laravel mix used for?, but it is just a guide map:

{
??"/js/app.js":?"/js/app.js",
??"/css/app.css":?"/css/app.css"
}

For users who have used Elixir before, another An interesting change: your build What is laravel mix used for?s now end up in the normal output directory, rather than a separate build directory, so your versioned JS What is laravel mix used for?s will appear in public/js/app-86ff5d31a2.js .

To enable cache busting in Mix, just append .version() to the Mix What is laravel mix used for?:

mix.js('resources/assets/js/app.js',?'public/js')
????.sass('resources/assets/sass/app.scss',?'public/css')
????.version();

This is much simpler than passing the actual What is laravel mix used for?name, Just like in Elixir.

mix() Help

As mentioned above, you want to use mix() instead of elixir() to reference your resources, which works exactly the same way. But there is one thing. If you use Mix, you need to delete these default reference lines in the Laravel template:

<link>
...
<script></script>

Replace them in the following way:

<link>
...
<script></script>

Remember, this function is only in ## Find the string in #mix-manifest.json and return the mapped build What is laravel mix used for?. Used to ensure that when you clear the cache, it knows how to load the default What is laravel mix used for?.

代碼拆分

Webpack 是對許多人來說很令人興奮的部分,因為它提供了使代碼結(jié)構(gòu)化的智能能力。我還沒能完全弄明白 webpack 的所有功能,Mix 也沒把所有功能都打包支持,例如:tree-shaking。但它確實使你的自定義代碼(它可能會經(jīng)常更改)與你的供應(yīng)商代碼(這不應(yīng)該)區(qū)分,使得用戶在每次推送新版本時刷新所有供應(yīng)商代碼的可能性更小。

要利用這個特性,你需要使用 extract() 函數(shù),它將你定義一個給定的庫或者模塊集合提取到一個單獨的構(gòu)建文件名為 vendor.js

mix.js('resources/assets/js/app.js',?'public/js')
????.extract(['vue',?'jquery']);

在這種情況下,Mix 生成了三個文件:public/js/app.js 、public/js/vendor.js ?和第三個 Webpack 特定文件 public/js/manifest.js。 為了運行順利,得按照以下的順序引入這三個文件:

<script></script>
<script></script>
<script></script>

如果清除了緩存,并且更改了應(yīng)用自定義的代碼, vendor.js ?文件仍會緩存,也只有應(yīng)用自定義的代碼才會被清除緩存,這樣你的網(wǎng)站會加載得更快。

自定義 Webpack 配置

如果你有興趣添加自己的自定義 Webpack 配置,只需要傳遞你的 Webpack 配置:

mix.webpackConfig({
????resolve:?{
????????modules:?[
????????????path.resolve(__dirname,?'vendor/laravel/spark/resources/assets/js')
????????]
????}
});

(上面這個例子只是從文檔復(fù)制粘貼來的~ 你真的有興趣就自己去了解哈~)

順便一提

說點有趣的東西吧,我想這或許能在 Webpack 文件中加點什么。 如果你想只在生產(chǎn)環(huán)境下復(fù)制點什么,你怎么會這樣做?

會這么問是因為我發(fā)現(xiàn)在 Node 環(huán)境對象中,我們可以用 process.env 去訪問??梢詸z查任何值,包括系統(tǒng)上的任何全局環(huán)境變量。這個發(fā)現(xiàn)可能可以讓我們?nèi)プ鳇c其他有趣的事情,比如說有條件地檢查 process.env.NODE_ENV ?中的值:

if?(process.env.NODE_ENV?==?'production')?{
????mix.webpackConfig({?...?});
}

但是在閱讀源代碼后,我發(fā)現(xiàn) NODE_ENV 不是主要的檢查。相反,是用了一個帶有 inProduction ?標(biāo)志的配置對象去做這件事情。 這個文檔里沒有寫,因此請謹(jǐn)慎使用,但你可以更新 Webpack 文件頂部的導(dǎo)入,然后使用該配置對象:

const?{?mix,?config?}?=?require('laravel-mix');

if?(config.inProduction)?{
????mix.webpackConfig({?...?});????
}

默認(rèn)依賴關(guān)系

你可以查看 package.json ?并查看每個項目包含的依賴項列表。 記住,這些是由默認(rèn)的 app.jsbootstrap.js ?來引用的,你可以刪除 app.js ?和 package.json ?中的引用,并重新運行 npm install ,當(dāng)然刪除引用并不會刪除源文件。

  • Axios(一個簡單且漂亮的 HTTP 客戶端)

  • Bootstrap Sass(由默認(rèn)的 app.scss ?文件來引入 Bootstrap 樣式)

  • jQuery

  • Lodash( 比 Underscore 更好)

  • Vue 2

小結(jié)

Laravel Mix 是一個代替 Laravel Elixir 的構(gòu)建工具。 具有與 Elixir 幾乎相同的API,卻是基于 Webpack 而不是 Gulp。? ? ? ? ? ? ?

【相關(guān)推薦:laravel視頻教程

The above is the detailed content of What is laravel mix used for?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
Object-Relational Mapping (ORM) Performance Tuning in PHP Object-Relational Mapping (ORM) Performance Tuning in PHP Jul 29, 2025 am 05:00 AM

Avoid N 1 query problems, reduce the number of database queries by loading associated data in advance; 2. Select only the required fields to avoid loading complete entities to save memory and bandwidth; 3. Use cache strategies reasonably, such as Doctrine's secondary cache or Redis cache high-frequency query results; 4. Optimize the entity life cycle and call clear() regularly to free up memory to prevent memory overflow; 5. Ensure that the database index exists and analyze the generated SQL statements to avoid inefficient queries; 6. Disable automatic change tracking in scenarios where changes are not required, and use arrays or lightweight modes to improve performance. Correct use of ORM requires combining SQL monitoring, caching, batch processing and appropriate optimization to ensure application performance while maintaining development efficiency.

VSCode settings.json location VSCode settings.json location Aug 01, 2025 am 06:12 AM

The settings.json file is located in the user-level or workspace-level path and is used to customize VSCode settings. 1. User-level path: Windows is C:\Users\\AppData\Roaming\Code\User\settings.json, macOS is /Users//Library/ApplicationSupport/Code/User/settings.json, Linux is /home//.config/Code/User/settings.json; 2. Workspace-level path: .vscode/settings in the project root directory

Building Immutable Objects in PHP with Readonly Properties Building Immutable Objects in PHP with Readonly Properties Jul 30, 2025 am 05:40 AM

ReadonlypropertiesinPHP8.2canonlybeassignedonceintheconstructororatdeclarationandcannotbemodifiedafterward,enforcingimmutabilityatthelanguagelevel.2.Toachievedeepimmutability,wrapmutabletypeslikearraysinArrayObjectorusecustomimmutablecollectionssucha

How to implement a referral system in Laravel? How to implement a referral system in Laravel? Aug 02, 2025 am 06:55 AM

Create referrals table to record recommendation relationships, including referrals, referrals, recommendation codes and usage time; 2. Define belongsToMany and hasMany relationships in the User model to manage recommendation data; 3. Generate a unique recommendation code when registering (can be implemented through model events); 4. Capture the recommendation code by querying parameters during registration, establish a recommendation relationship after verification and prevent self-recommendation; 5. Trigger the reward mechanism when recommended users complete the specified behavior (subscription order); 6. Generate shareable recommendation links, and use Laravel signature URLs to enhance security; 7. Display recommendation statistics on the dashboard, such as the total number of recommendations and converted numbers; it is necessary to ensure database constraints, sessions or cookies are persisted,

css dark mode toggle example css dark mode toggle example Jul 30, 2025 am 05:28 AM

First, use JavaScript to obtain the user system preferences and locally stored theme settings, and initialize the page theme; 1. The HTML structure contains a button to trigger topic switching; 2. CSS uses: root to define bright theme variables, .dark-mode class defines dark theme variables, and applies these variables through var(); 3. JavaScript detects prefers-color-scheme and reads localStorage to determine the initial theme; 4. Switch the dark-mode class on the html element when clicking the button, and saves the current state to localStorage; 5. All color changes are accompanied by 0.3 seconds transition animation to enhance the user

Java Performance Optimization and Profiling Techniques Java Performance Optimization and Profiling Techniques Jul 31, 2025 am 03:58 AM

Use performance analysis tools to locate bottlenecks, use VisualVM or JProfiler in the development and testing stage, and give priority to Async-Profiler in the production environment; 2. Reduce object creation, reuse objects, use StringBuilder to replace string splicing, and select appropriate GC strategies; 3. Optimize collection usage, select and preset initial capacity according to the scene; 4. Optimize concurrency, use concurrent collections, reduce lock granularity, and set thread pool reasonably; 5. Tune JVM parameters, set reasonable heap size and low-latency garbage collector and enable GC logs; 6. Avoid reflection at the code level, replace wrapper classes with basic types, delay initialization, and use final and static; 7. Continuous performance testing and monitoring, combined with JMH

How to build a REST API with Laravel? How to build a REST API with Laravel? Jul 30, 2025 am 03:41 AM

Create a new Laravel project and start the service; 2. Generate the model, migration and controller and run the migration; 3. Define the RESTful route in routes/api.php; 4. Implement the addition, deletion, modification and query method in PostController and return the JSON response; 5. Use Postman or curl to test the API function; 6. Optionally add API authentication through Sanctum; finally obtain a clear structure, complete and extensible LaravelRESTAPI, suitable for practical applications.

What is Eloquent ORM in Laravel? What is Eloquent ORM in Laravel? Jul 29, 2025 am 03:50 AM

EloquentORM is Laravel's built-in object relational mapping system. It operates the database through PHP syntax instead of native SQL, making the code more concise and easy to maintain; 1. Each data table corresponds to a model class, and each record exists as a model instance; 2. Adopt active record mode, and the model instance can be saved or updated by itself; 3. Support batch assignment, and the $fillable attribute needs to be defined in the model to ensure security; 4. Provide strong relationship support, such as one-to-one, one-to-many, many-to-many, etc., and you can access the associated data through method calls; 5. Integrated query constructor, where, orderBy and other methods can be called chained to build queries; 6. Support accessors and modifiers, which can format the number when obtaining or setting attributes.

See all articles