I'm having a problem with Laravel-Mix on my Laravel-Vue SPA: when I try to run npm run prod, PostCSS produces an Unknown Word error. After hours of messing around, I finally figured out this has to do with double slash '//' comments in some of my Vue components and SCSS files. As these comments are not allowed in CSS language, PostCSS throws an error for every single one of them. Now I could of course easily replace all these comments and replace them with proper CSS comments, but I was wondering if there is a workaround or solution to fix this problem and be able to use '//' comments with Laravel-Mix. This is my webpack.mix.js:
const fs = require('fs-extra')
const mix = require('laravel-mix')
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
mix
.js('resources/js/app.js', 'public/dist/js')
.sass('resources/sass/app.scss', 'public/dist/css')
.disableNotifications()
if (mix.inProduction()) {
require('laravel-mix-versionhash')
mix.versionHash()
} else {
mix.sourceMaps()
}
mix.sourceMaps()
mix.webpackConfig({
plugins: [
// new BundleAnalyzerPlugin()
],
resolve: {
extensions: ['.js', '.json', '.vue'],
alias: {
'~': path.join(__dirname, './resources/js')
}
},
output: {
chunkFilename: 'dist/js/[chunkhash].js',
path: mix.config.hmr ? '/' : path.resolve(__dirname, './public/build')
}
})
mix.then(() => {
if (!mix.config.hmr) {
process.nextTick(() => publishAssets())
}
})
function publishAssets () {
const publicDir = path.resolve(__dirname, './public')
if (mix.inProduction()) {
fs.removeSync(path.join(publicDir, 'dist'))
}
fs.copySync(path.join(publicDir, 'build', 'dist'), path.join(publicDir, 'dist'))
fs.removeSync(path.join(publicDir, 'build'))
}