乍一看,一切似乎都可以与BrowserSync一起使用。它已成功在localhost:3000代理我的服务器。当我对文件(例如resources/styles/app.scss
)进行更改时,它声称正在对其进行编译:
[Browsersync] Proxying: http://magnetar.localhost
[Browsersync] access URLs:
-------------------------------------
Local: http://localhost:3000
External: http://192.168.56.1:3000
-------------------------------------
UI: http://localhost:3001
UI External: http://localhost:3001
-------------------------------------
[Browsersync] Watching files...
WAIT Compiling...7:00:42 AM
[Browsersync] Reloading Browsers...
DONE Compiled successfully in 39728ms7:01:22 AM
[Browsersync] Reloading Browsers... (buffered 2 events)
浏览器自动刷新,但是没有什么不同。实际上,对文件dist/styles/app.css
的检查表明我在SCSS文件中所做的更改不存在,因此BrowserSync到底在编译什么?!
我正在使用Webpack和Laravel Mix。这是我的配置文件:
const mix = require( 'laravel-mix' );
// Public path helper
const publicPath = path => `${mix.config.publicPath}/${path}`;
// Source path helper
const src = path => `resources/assets/${path}`;
// Public Path
mix
.setPublicPath( './dist' )
.setResourceRoot( `/wp-content/themes/magnetar/${mix.config.publicPath}/` )
.webpackConfig( {
output : { publicPath : mix.config.resourceRoot },} );
// Styles
mix.sass( src`styles/app.scss`,'styles' );
// Assets
mix.copyDirectory( src`images`,publicPath`images` )
.copyDirectory( src`fonts`,publicPath`fonts` );
// JavaScript
mix.js( src`scripts/app.js`,'scripts' );
//.extract();
// Autoload
/*mix.autoload( {
jquery : [ '$','window.jQuery' ],} );*/
// Source maps when not in production.
mix.sourceMaps( false,'source-map' );
// Hash and version files in production.
if ( mix.inProduction() ) {
require( 'laravel-mix-versionhash' );
mix.versionHash( { length : 16 } );
}
// Browsersync
mix.browserSync( {
files : [ 'dist/**/*','resources/**/*' ],proxy : 'magnetar.localhost'
} );