Last active
August 13, 2022 00:52
-
-
Save seafarer/e45ac8608743d0d634105077f801124e to your computer and use it in GitHub Desktop.
Use Laravel Mix with a basic WordPress theme like Underscores. So much easier than messing around with Gulp etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Take advantage of Mix's cache busting function | |
*/ | |
function asset( $path ) { | |
// Asset manifest file from Mix | |
$manifest = get_template_directory_uri() . '/dist/mix-manifest.json'; | |
$manifest_array = json_decode(file_get_contents($manifest), true); | |
//Full asset path | |
return get_template_directory_uri() . '/dist' . $manifest_array[$path]; | |
} | |
/** | |
* Enqueue scripts and styles. | |
*/ | |
function mysite_scripts() { | |
wp_enqueue_style( 'app-style', asset('/css/style.css'), array(), null ); | |
wp_enqueue_script( 'app-scripts', asset('/js/scripts.js'), array('jquery'), null, true ); | |
} | |
add_action( 'wp_enqueue_scripts', 'mysite_scripts' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"laravel-mix": "^6.0.44", | |
}, | |
"devDependencies": { | |
"browser-sync": "^2.27.10", | |
"browser-sync-webpack-plugin": "^2.3.0", | |
"copy-webpack-plugin": "^5.1.1", | |
"imagemin-webpack-plugin": "^2.4.2", | |
"laravel-mix-imagemin": "^1.0.3", | |
"resolve-url-loader": "^5.0.0", | |
"sass": "^1.52.1", | |
"sass-loader": "^12.1.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://laravel-mix.com/docs/6.0/installation | |
// `npx mix` to compile | |
// `npx mix watch` to run browsersync and watch files | |
let mix = require('laravel-mix'); | |
require('laravel-mix-imagemin'); | |
mix | |
.setPublicPath('dist') | |
.browserSync({ | |
proxy: 'mysite.test', | |
files: ['./**/*.php', './**/*.js', './**/*.scss'] | |
}); | |
mix | |
.js('./src/js/scripts.js', 'js').version() | |
mix | |
.sass('./src/scss/style.scss', 'css').version() | |
.options({ | |
processCssUrls: false | |
}) | |
.sourceMaps(true, 'source-map'); | |
mix.imagemin(['./img/**.*', './img/icon/**.*']); | |
mix.disableNotifications(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment