Last active
October 13, 2020 17:58
-
-
Save Aslam97/dede5470f81c6e1a38cc1326aaf8af62 to your computer and use it in GitHub Desktop.
Laravel Mix webpack.mix.js simple configuration
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
const path = require("path"); | |
const mix = require("laravel-mix"); | |
mix.alias({ | |
"@": path.join(__dirname, "resources/js"), | |
"~": path.join(__dirname, "resources/sass"), | |
}); | |
mix | |
.js("resources/js/app.js", "public/js") | |
.sass("resources/sass/app.scss", "public/css"); | |
mix.autoload({ | |
jquery: ["$", "jQuery", "window.jQuery"] | |
}); | |
mix.vue({ version: 2 }); | |
mix.webpackConfig({ | |
output: { | |
publicPath: "/", | |
chunkFilename: mix.inProduction() | |
? "js/chunks/[chunkhash].js" | |
: "js/chunks/[name].js" | |
}, | |
module: { | |
rules: [ | |
{ | |
// disabled hash for using preload fonts | |
test: /(\.(woff2?|ttf|eot|otf)$|font.*\.svg$)/, | |
use: [ | |
{ | |
loader: "file-loader", | |
options: { | |
name: path => { | |
if (!/node_modules|bower_components/.test(path)) { | |
return "fonts/[name].[ext]"; | |
} | |
const pathUpdated = path | |
.replace(/\\/g, "/") | |
.replace( | |
/((.*(node_modules|bower_components))|fonts|font|assets)\//g, | |
"" | |
); | |
return `fonts/vendor/${pathUpdated}`; | |
} | |
} | |
} | |
] | |
} | |
] | |
} | |
}); | |
mix.options({ | |
processCssUrls: true, | |
postCss: [ | |
mix.inProduction() | |
? require("@fullhuman/postcss-purgecss")({ | |
content: ["resources/**/*.blade.php", "resources/**/*.vue"], | |
defaultExtractor: content => content.match(/[\w-/.:]+(?<!:)/g) || [], | |
safelist: { | |
greedy: [ | |
/-active$/, | |
/-enter$/, | |
/-leave-to$/, | |
/show$/ | |
] | |
} | |
}) | |
: undefined | |
], | |
terser: { | |
// remove LICENSE | |
extractComments: false | |
}, | |
autoprefixer: {}, | |
cssName: {} | |
}); | |
mix.extract(); | |
// mix.disableNotifications(); | |
if (mix.inProduction()) { | |
mix.version(); | |
} else { | |
mix.dump(); | |
mix.sourceMaps(true, "source-map"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment