Skip to content

Instantly share code, notes, and snippets.

@mckenziearts
Created January 15, 2021 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mckenziearts/1bb6884720278586fab81aa363bd77e8 to your computer and use it in GitHub Desktop.
Save mckenziearts/1bb6884720278586fab81aa363bd77e8 to your computer and use it in GitHub Desktop.
Laravel webpack mix example
const mix = require('laravel-mix');
const path = require('path');
/*
|--------------------------------------------------------------------------
| 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.
|
*/
mix.setPublicPath("public")
.js('resources/js/app.js', 'public/js')
.postCss("resources/css/app.css", "public/css", [
require("tailwindcss"),
])
.options({ processCssUrls: false })
.webpackConfig({
output: { chunkFilename: 'js/[name].js?id=[chunkhash]' },
resolve: {
extensions: ["*", ".js", ".jsx"],
alias: {
'@': path.resolve('./resources/js'),
},
}
})
.sourceMaps();
if (mix.inProduction()) {
mix.version()
.options({
// optimize js minification process
terser: {
cache: true,
parallel: true,
sourceMap: true
}
});
} else {
// Uses inline source-maps on development
mix.webpackConfig({ devtool: "inline-source-map" });
}
const mix = require('laravel-mix');
const path = require('path');
require('laravel-mix-tailwind');
/*
|--------------------------------------------------------------------------
| 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.
|
*/
mix.setPublicPath("public")
.js('resources/js/app.js', 'public/js')
.sass("./resources/sass/app.scss", "public/css")
.tailwind("./tailwind.config.js")
.options({ processCssUrls: false })
.webpackConfig({
output: { chunkFilename: 'js/[name].js?id=[chunkhash]' },
resolve: {
extensions: ["*", ".js", ".jsx"],
alias: {
'@': path.resolve('./resources/js'),
},
}
})
.sourceMaps();
if (mix.inProduction()) {
mix.version()
.options({
// optimize js minification process
terser: {
cache: true,
parallel: true,
sourceMap: true
}
});
} else {
// Uses inline source-maps on development
mix.webpackConfig({ devtool: "inline-source-map" });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment