-
-
Notifications
You must be signed in to change notification settings - Fork 90
Laravel Mix #1
Comments
I'm occurring in a lot of errors when using code splitting with this. Mix keeps creating a |
Not at all. Not sure why that would be happening honestly. |
I can see there's a few active issues on their repo about this. It all boils down on how mix uses the publicPath. Weird enough though, even when I override this, the whole thing breaks down 😢 Edit: after a couple of hours of battling with this, it's definitely a publicPath issue in mix. When specified to work with a |
I've been playing around with Laravel Mix and Vuejs as a default setup with Sage and I would really like to have the option to install a fresh version of Sage with Laravel Mix and Vuejs as a preset. It's been working out fine for me so far, built a few websites using this version of Sage. Not sure how to go about creating a preset for the installer though 🙄 |
I've worked with Mix on some Laravel apps and my first use in a stand-alone was with a new WordPress install. Got everything working fairly easy, except couldn't nail the public path part. But, that seemed to be a big issue for a number of folk over at the Mix repository. Out of the blue, I found @Log1x Mix configs on Sage Issue #1868 -- which is now closed. Lots of good information in that, I would like to add onto that and address some concerns. Getting the path right let path = require('path');
const rootPath = path.join(__dirname, '..');
const app = 'app';
const resources = 'resources';
const assets = 'resources/assets';
const dist = 'dist';
mix.setPublicPath(dist);
mix.setResourceRoot(rootPath); Copying assets // Assets
mix.copyDirectory(`${assets}/images`, `${dist}/images`);
.copyDirectory(`${assets}/fonts`, `${dist}/fonts`); Cross-OS package.json scripts "scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"cross-env": "^5.0.5",
}, That is the stock Mix setup. For the normal Sage Yarn-ers, add the following aliases.
Working with versioning in Blade mix.js('resources/assets/js/app.js', 'dist/js');
if (mix.inProduction()) {
mix.version();
} In your Blade views, use the <script src="{{ mix('/js/app.js') }}"></script> Note that this is similar to the Caveat: Only problem here is that this will not work with Over-riding the stock Webpack config
Edge case scenario I basically, grabbed all of the css/js stuff and HTML snapshots of a few pages. Dumped all of the non-dev tracking, ads, special plugin code (like the megamenu). This is all dumped into a single folder I move the main stylesheet and minified bootstrap (yup, easier this way) into the root of my Here are my Mix config and App\Setup for enqueing side-by-side, which BTW, kind of aids in development. It is really easy to compare with your enqueues. /**
* Theme assets
*/
add_action('wp_enqueue_scripts', function () {
// Styles
wp_enqueue_style('sage-bootstrap', asset_path('styles/bootstrap.min.css'), false, null);
// wp_enqueue_style('sage-parallax', asset_path('styles/parallax/parallax.css'), ['sage-bootstrap'], null, true);
wp_enqueue_style('sage-main', asset_path('styles/main.css'), ['sage-bootstrap'], null, null);
wp_enqueue_style('sage-style', asset_path('styles/style.css'), ['sage-main'], null, null);
// Scripts
wp_enqueue_script('sage-bootstrap', asset_path('scripts/bootstrap.min.js'), ['jquery'], null);
wp_enqueue_script('sage-parallax', asset_path('scripts/parallax.js'), ['jquery'], null);
wp_enqueue_script('sage-js', asset_path('scripts/main.js'), ['jquery', 'sage-bootstrap'], null);
}, 100); // Assets
mix.copyDirectory(`${assets}/images`, `${dist}/images`);
mix.copyDirectory(`${assets}/fonts`, `${dist}/fonts`);
// Styles
mix.copyDirectory(`${resources}/parallax/*.css`, `${dist}/styles/parallax`)
.copy(`${assets}/styles/bootstrap.min.css`, `${dist}/styles`)
.sass(`${assets}/styles/main.scss`, `${dist}/styles`)
.copy(`${assets}/styles/style.css`, `${dist}/styles`);
// Scripts
mix.js(`${assets}/scripts/main.js`, `${dist}/scripts`)
.js(`${assets}/scripts/customizer.js`, `${dist}/scripts`)
.copy(`${assets}/scripts/bootstrap.min.js`, `${dist}/scripts`)
.combine(`${assets}/scripts/parallax/*.js`, `${dist}/scripts/parallax.js`);
// PostCSS
mix.options({
processCssUrls: false,
}); Note the Well this turned into a longer winded post than it should have been. Hopefully somebody will get some use out of it. |
@webstractions re:
I fixed this, perhaps in not the most elegant way, by changing this line in -- 'manifest' => get_theme_file_path().'/dist/assets.json',
++ 'manifest' => get_theme_file_path().'/dist/mix-manifest.json', And by modifying Sage's /**
* @param $asset
* @return string
*/
function asset_path($asset)
{
-- return sage('assets')->getUri('/' . $asset);
++ return str_replace('/dist//', '/dist/', sage('assets')->getUri('/' . $asset));
} This normalizes for Laravel Mix's practice of adding a leading slash to the asset paths in These two changes let me use Mix without having to patch |
@greatislander Cool. I had already revised the manifest. Didn't know about the With that said, how would you go about doing |
My Mix file looks somewhat like this now... const mix = require('laravel-mix');
const ImageminPlugin = require('imagemin-webpack-plugin').default;
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
const app = 'app';
const config = 'config';
const resources = 'resources';
const assets = `${resources}/assets`;
const dist = 'dist';
mix.setPublicPath(dist);
mix.setResourceRoot('../');
// Browser Sync
mix.browserSync({
host: 'localhost',
proxy: 'https://flux.dev',
port: 3000,
browser: ['firefox.exe'],
files: [
`${app}/**/*.php`,
`${config}/**/*.php`,
`${resources}/views/**/*.php`,
`${dist}/styles/**.css`,
`${dist}/scripts/**.js`
]
});
// Stylus
mix.stylus(`${assets}/styles/wrapper.styl`, `${dist}/styles/main.css`)
.stylus(`${assets}/styles/wordpress/editor.styl`, `${dist}/styles/editor.css`)
.stylus(`${assets}/styles/wordpress/admin/wrapper.styl`, `${dist}/styles/admin.css`)
.stylus(`${assets}/styles/wordpress/login/wrapper.styl`, `${dist}/styles/login.css`);
// Javascript
mix.js(`${assets}/scripts/main.js`, `${dist}/scripts`)
.js(`${assets}/scripts/tinymce.js`, `${dist}/scripts`)
.extract([
'jquery-sticky/jquery.sticky',
'readmore-js/readmore.min'
]);
// Assets
mix.copyDirectory(`${assets}/fonts`, `${dist}/fonts`)
.copyDirectory(`${assets}/images`, `${dist}/images`)
.copyDirectory(`${assets}/favicons`, `${dist}/favicons`);
// Autoload
mix.autoload({
jquery: ['$', 'window.jQuery', 'jQuery']
});
// Options
mix.options({
processCssUrls: false,
postCss: [
require('rucksack-css')()
]
});
// Additional Configuration
mix.webpackConfig({
plugins: [
new ImageminPlugin({
pngquant: {
quality: '95-100'
},
test: /\.(jpe?g|png|gif|svg)$/i
})
]
});
// Source maps when not in production.
if (!mix.inProduction()) {
mix.sourceMaps();
}
// Hash and version files in production.
if (mix.inProduction()) {
mix.version();
}
My scripts: "scripts": {
"build": "NODE_ENV=development webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"build:production": "npm run -s clean && NODE_ENV=production webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js && npm run -s build:views",
"build:views": "wp blade compile",
"build:fonts": "icon-font-generator resources/assets/fonts/icons/src/svg/**/*.svg --out 'resources/assets/fonts/icons/' --csstp 'resources/assets/fonts/icons/src/config.hbs' --csspath 'resources/assets/styles/config/icons.styl' --html 'false' --json 'false'",
"start": "NODE_ENV=development webpack --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"clean": "npm run -s clean:cache && npm run -s clean:dist",
"clean:cache": "rimraf resources/cache",
"clean:dist": "rimraf dist",
"lint": "npm run -s lint:scripts && npm run -s lint:styles",
"lint:scripts": "eslint resources/assets/scripts",
"lint:styles": "stylelint 'resources/assets/styles/**/*.{css,styl,sass,scss,less}'",
"test": "npm run -s lint"
}, |
@webstractions For
The -- /app/themes/sage/dist//styles/main.css
++ /app/themes/sage/dist/styles/main.css |
@greatislander Okay. It is all clear now. Forgot about the On a side note, I was checking out
After investigating a bit, all of those helpers get routed through Since Been playing with BrowserSync. Love that
Then
|
@webstractions Yeah, I didn't try using |
we'll be switching to laravel mix as the default instead of making it an option during install roots/sage#2011 |
Really liking how sage-installer looks so far. Also +1 for adding Bulma.
Following up from sage Issue #1868.
My comment on the issue seen here gives exaggerated defaults that work with Sage that can most definitely be simplified.
Would like to see an option for Laravel Mix implemented. :)
Thanks in advance.
The text was updated successfully, but these errors were encountered: