Skip to content

Commit fb7bb08

Browse files
committed
feat: sync 20170223 but have not translate
1 parent aaacb76 commit fb7bb08

File tree

1 file changed

+125
-15
lines changed

1 file changed

+125
-15
lines changed

mix.md

Lines changed: 125 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
- [使用样式](#working-with-stylesheets)
77
- [Less](#less)
88
- [Sass](#sass)
9+
- [Stylus](#stylus)
10+
- [PostCSS](#postcss)
911
- [纯 CSS](#plain-css)
12+
- [URL Processing](#url-processing)
1013
- [资源地图](#css-source-maps)
1114
- [使用脚本](#working-with-scripts)
12-
- [代码分割](#code-splitting)
13-
- [自定义 Webpack 配置](#custom-webpack-configuration)
15+
- [Vendor Extraction](#vendor-extraction)
16+
- [React](#react-support)
17+
- [Vanilla JS](#vanilla-js)
18+
- [自定义 Webpack 配置](#custom-webpack-configuration)
1419
- [复制文件与目录](#copying-files-and-directories)
1520
- [版本与缓存清除](#versioning-and-cache-busting)
21+
- [Browsersync Reloading](#browsersync-reloading)
1622
- [通知](#notifications)
1723

1824
<a name="introduction"></a>
@@ -66,6 +72,10 @@ Mix 基于 [Webpack](https://webpack.js.org) 的配置, 所以运行定义于
6672

6773
npm run watch
6874

75+
You may find that in certain environments Webpack isn't updating when your files change. If this is the case on your system, consider using the `watch-poll` command:
76+
77+
npm run watch-poll
78+
6979
<a name="working-with-stylesheets"></a>
7080
## 使用样式
7181

@@ -87,6 +97,12 @@ Mix 基于 [Webpack](https://webpack.js.org) 的配置, 所以运行定义于
8797

8898
mix.less('resources/assets/less/app.less', 'public/stylesheets/styles.css');
8999

100+
If you need to override the [underlying Less plug-in options](https://github.com/webpack-contrib/less-loader#options), you may pass an object as the third argument to `mix.less()`:
101+
102+
mix.less('resources/assets/less/app.less', 'public/css', {
103+
strictMath: true
104+
});
105+
90106
<a name="sass"></a>
91107
### Sass
92108

@@ -99,16 +115,79 @@ Mix 基于 [Webpack](https://webpack.js.org) 的配置, 所以运行定义于
99115
mix.sass('resources/assets/sass/app.sass', 'public/css')
100116
.sass('resources/assets/sass/admin.sass', 'public/css/admin');
101117

118+
Additional [Node-Sass plug-in options](https://github.com/sass/node-sass#options) may be provided as the third argument:
119+
120+
mix.sass('resources/assets/less/app.less', 'public/css', {
121+
precision: 5
122+
});
123+
124+
<a name="stylus"></a>
125+
### Stylus
126+
127+
Similar to Less and Sass, the `stylus` method allows you to compile [Stylus](http://stylus-lang.com/) into CSS:
128+
129+
mix.stylus('resources/assets/sass/app.scss', 'public/css');
130+
131+
You may also install additional Stylus plug-ins, such as [Rupture](https://github.com/jescalan/rupture). First, install the plug-in in question through NPM (`npm install rupture`) and then require it in your call to `mix.stylus()`:
132+
133+
mix.stylus('resources/assets/stylus/app.styl', 'public/css', {
134+
use: [
135+
require('rupture')()
136+
]
137+
});
138+
139+
<a name="postcss"></a>
140+
### PostCSS
141+
142+
[PostCSS](http://postcss.org/), a powerful tool for transforming your CSS, is included with Laravel Mix out of the box. By default, Mix leverages the popular [Autoprefixer](https://github.com/postcss/autoprefixer) plug-in to automatically apply all necessary CSS3 vendor prefixes. However, you're free to add any additional plug-ins that are appropriate for your application. First, install the desired plug-in through NPM and then reference it in your `webpack.mix.js` file:
143+
144+
mix.sass('resources/assets/sass/app.scss', 'public/css')
145+
.options({
146+
postCss: [
147+
require('postcss-css-variables')()
148+
]
149+
});
150+
102151
<a name="plain-css"></a>
103152
### 纯 CSS
104153

105-
如果你只是想将一些纯 CSS 样式合并成单个的文件, 你可以使用 `combine` 方法。此方法同样支持合并 JavaScript 文件:
154+
如果你只是想将一些纯 CSS 样式合并成单个的文件, 你可以使用 `styles` 方法。
106155

107-
mix.combine([
156+
mix.styles([
108157
'public/css/vendor/normalize.css',
109158
'public/css/vendor/videojs.css'
110159
], 'public/css/all.css');
111160

161+
<a name="url-processing"></a>
162+
### URL Processing
163+
164+
Because Laravel Mix is built on top of Webpack, it's important to understand a few Webpack concepts. For CSS compilation, Webpack will rewrite and optimize any `url()` calls within your stylesheets. While this might initially sound strange, it's an incredibly powerful piece of functionality. Imagine that we want to compile Sass that includes a relative URL to an image:
165+
166+
.example {
167+
background: url('../images/example.png');
168+
}
169+
170+
> {note} Absolute paths for `url()`s will be excluded from URL-rewriting. For example, `url('/images/thing.png')` or `url('http://example.com/images/thing.png')` won't be modified.
171+
172+
By default, Laravel Mix and Webpack will find `example.png`, copy it to your `public/images` folder, and then rewrite the `url()` within your generated stylesheet. As such, your compiled CSS will be:
173+
174+
.example {
175+
background: url(/images/example.png?d41d8cd98f00b204e9800998ecf8427e);
176+
}
177+
178+
As useful as this feature may be, it's possible that your existing folder structure is already configured in a way you like. If this is the case, you may disable `url()` rewriting like so:
179+
180+
mix.sass('resources/assets/app/app.scss', 'public/css')
181+
.options({
182+
processCssUrls: false
183+
});
184+
185+
With this addition to your `webpack.mix.js` file, Mix will no longer match `url()`s or copy assets to your public directory. In other words, the compiled CSS will look just like how you originally typed it:
186+
187+
.example {
188+
background: url("../images/thing.png");
189+
}
190+
112191
<a name="css-source-maps"></a>
113192
### 资源地图
114193

@@ -128,12 +207,13 @@ Mix 也提供了一些函数来帮助你使用 JavaScript 文件,像是编译
128207

129208
<div class="content-list" markdown="1">
130209
- ECMAScript 2015 语法.
210+
- Modules
131211
- 编译 `.vue` 文件.
132212
- 针对生产环境压缩代码.
133213
</div>
134214

135-
<a name="code-splitting"></a>
136-
### 代码分割
215+
<a name="vendor-extraction"></a>
216+
### Vendor Extraction
137217

138218
将应用程序的 JavaScript 与依赖库捆绑在一起的一个潜在缺点是,使得长期缓存更加困难。如,对应用程序代码的单独更新将强制浏览器重新下载所有依赖库,即使它们没有更改。
139219

@@ -156,6 +236,29 @@ Mix 也提供了一些函数来帮助你使用 JavaScript 文件,像是编译
156236
<script src="/js/vendor.js"></script>
157237
<script src="/js/app.js"></script>
158238

239+
<a name="react"></a>
240+
### React
241+
242+
Mix can automatically install the Babel plug-ins necessary for React support. To get started, replace your `mix.js()` call with `mix.react()`:
243+
244+
mix.react('resources/assets/js/app.jsx', 'public/js');
245+
246+
Behind the scenes, React will download and include the appropriate `babel-preset-react` Babel plug-in.
247+
248+
<a name="vanilla-js"></a>
249+
### Vanilla JS
250+
251+
Similar to combining stylesheets with `mix.styles()`, you may also combine and minify any number of JavaScript files with the `scripts()` method:
252+
253+
mix.scripts([
254+
'public/js/admin.js',
255+
'public/js/dashboard.js'
256+
], 'public/js/all.js');
257+
258+
This option is particularly useful for legacy projects where you don't require Webpack compilation for your JavaScript.
259+
260+
> {tip} A slight variation of `mix.scripts()` is `mix.babel()`. Its method signature is identical to `scripts`; however, the concatenated file will receive Babel compilation, which translates any ES2015 code to vanilla JavaScript that all browsers will understand.
261+
159262
<a name="custom-webpack-configuration"></a>
160263
### 自定义 Webpack 配置
161264

@@ -173,15 +276,6 @@ Mix 提供了一个有用的 `webpackConfig` 方法,允许合并任何 `Webpac
173276
}
174277
});
175278

176-
177-
#### 自己维护配置文件
178-
179-
第二个是将 Mix 的 `webpack.config.js` 复制到项目根目录。
180-
181-
cp node_modules/laravel-mix/setup/webpack.config.js ./
182-
183-
接下来,你需要更新 `package.json` 中的 NPM 脚本,以确保不再直接引用默认的 Mix 的配置文件。需要从命令中删除 `--config="node_modules/laravel-mix/setup/webpack.config.js"`。之后,你就可以根据需要修改配置文件。
184-
185279
<a name="copying-files-and-directories"></a>
186280
## 复制文件与目录
187281

@@ -211,6 +305,22 @@ Mix 提供了一个有用的 `webpackConfig` 方法,允许合并任何 `Webpac
211305
mix.version();
212306
}
213307

308+
<a name="browsersync-reloading"></a>
309+
## Browsersync Reloading
310+
311+
[BrowserSync](https://browsersync.io/) can automatically monitor your files for changes, and inject your changes into the browser without requiring a manual refresh. You may enable support by calling the `mix.browserSync()` method:
312+
313+
mix.browserSync('my-domain.dev');
314+
315+
// Or...
316+
317+
// https://browsersync.io/docs/options
318+
mix.browserSync({
319+
proxy: 'my-domain.dev'
320+
});
321+
322+
You may pass either a string (proxy) or object (BrowserSync settings) to this method. Next, start Webpack's dev server using the `npm run watch` command. Now, when you modify a script or PHP file, watch as the browser instantly refreshes the page to reflect your changes.
323+
214324
<a name="notifications"></a>
215325
## 通知
216326

0 commit comments

Comments
 (0)