Laravel Mix BrowserSync It is not triggered - laravel

According to the Laravel Mix documents. I'm using Webpack to compile styles and launch BrowserSync in the process.
This is my complete webpack.mix.js document. You can see browserSync on line 92:
require('laravel-mix-merge-manifest');
const fs = require('fs');
const mix = require('laravel-mix');
const pathEnv = 'resources/sass/_enviroments/' + process.env.NODE_ENV;
const sites = [
'RP-ES',
'TZ-ES',
'CAL-ES',
'RUP-ES',
'FL-ES',
'SP-ES',
'WPX-IT',
'WPX-UK',
'WPX-CH',
'WPX-FR',
'WPX-DE',
'WPX-PT',
'WPX-NL',
'MTN-ES',
'MTN-DE',
'MTN-FR'
];
const tmpFiles = [];
try
{
if (process.env.NODE_ENV == 'development')
{
if (!process.env.hasOwnProperty('npm_config_only_css'))
generateJS();
if (!process.env.hasOwnProperty('npm_config_only_js'))
{
if (!process.env.hasOwnProperty('npm_config_site'))
{
// throw('In development, parameter "--site" is mandatory, one of the follow values: "'+sites.join('", "')+'"');
sites.forEach(slug=>{
generateSiteCss(slug)
});
}
else
generateSiteCss(process.env.npm_config_site);
}
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
mix.webpackConfig({plugins: [new BundleAnalyzerPlugin()]});
}
else
{
generateJS();
sites.forEach(slug=>{
generateSiteCss(slug)
});
}
mix.version()
mix.mergeManifest()
mix.then(deleteTmpFiles);
}
catch(e)
{
deleteTmpFiles();
throw e;
}
function generateJS()
{
console.log('Generating JS...');
// app scripts (common in all pages)
mix.js('resources/js/app.js', 'public/js')
.extract()
// individual scripts (auto register) to use alone en certain pages
.js('resources/js/components/helpcenter_results.vue.js', 'public/js/vue_components') // used in helpcenter
.js('resources/js/components/newsletter.vue.js', 'public/js/vue_components') // used in home
.js('resources/js/components/slick_carousel.vue.js', 'public/js/vue_components') // used in product pages & designs list
.js('resources/js/components/vue_tab.vue.js', 'public/js/vue_components') // used in login
// combined components with auto register included
.js('resources/js/products_page.js', 'public/js')
.js('resources/js/checkout.js', 'public/js')
.js('resources/js/payment_methods.js', 'public/js')
.js('resources/js/cart.js', 'public/js')
.js('resources/js/products_list.js', 'public/js')
.js('resources/js/accounts.js', 'public/js')
// required libs that are used in certain pages and are not available througth npm
.copyDirectory('resources/js/libs','public/js/libs')
.copyDirectory('resources/fonts','public/fonts')
.copyDirectory('resources/css','public/css')
.browserSync('regalospersonales.local');
}
function generateSiteCss(slug)
{
console.log('Generating CSS for the site: '+ slug +'...');
let pathSite = `resources/sass/_sites/${slug}`;
let outputPath = `public/css/sites/${slug}`;
let tmpPath = `resources/sass/${slug}`;
let includePaths = [
pathEnv,
pathSite
];
fs.writeFileSync(`${tmpPath}_common.scss`, `#import '_common';`);
fs.writeFileSync(`${tmpPath}_helpcenter.scss`, `#import '_helpcenter';`);
tmpFiles.push(`${tmpPath}_common.scss`);
tmpFiles.push(`${tmpPath}_helpcenter.scss`);
mix.sass(`${tmpPath}_common.scss`, `${outputPath}/common.css`, { includePaths: includePaths })
.sass(`${tmpPath}_helpcenter.scss`, `${outputPath}/helpcenter.css`, { includePaths: includePaths })
//.then(deleteTmpFiles)
//console.log(result);
//throw new Exception('asdfasdf');
}
function deleteTmpFiles(){
console.log('Deleting temporal files...');
tmpFiles.forEach(f=>{
if (fs.existsSync(f))
fs.unlinkSync(f);
});
}
And of course I have sync browser installed with my package.json:
"devDependencies": {
"browser-sync": "^2.26.7",
"browser-sync-webpack-plugin": "^2.0.1",
Everything looks good. But when I execute:
npm run watch
All my styles and javascript are compiled, watch is activated but it doesn't say anything about BrowserSync.
No error or anything happens, it's like BrowserSync is ignored.
What's going on?

Related

Postcss Advanced Variables could not resolve the mixin media-breakpoint-down error (Laravel / Tailwind)

I have a Laravel application with tailwind / postcss and when npm run dev is executed I get the following error:
postcss-advanced-variables: /var/www/html/resources/css/login.css Could not resolve the mixin for "media-breakpoint-down"
This is my webpack.mix.js file:
const process = require('process')
const mix = require('laravel-mix')
const cssImport = require('postcss-import')
const cssNesting = require('postcss-nesting')
const webpackConfig = require('./webpack.config')
/*
|--------------------------------------------------------------------------
| 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
.js('resources/js/app.js', 'public/js')
.vue({ runtimeOnly: (process.env.NODE_ENV || 'production') === 'production' })
.webpackConfig(webpackConfig)
.postCss('resources/css/app.css', 'public/css', [
// prettier-ignore
cssImport(),
require("postcss-advanced-variables"),
cssNesting(),
require('tailwindcss'),
require("autoprefixer"),
])
.version()
.sourceMaps()
and webpack.config.js file:
const path = require('path')
// https://stefanbauer.me/tips-and-tricks/autocompletion-for-webpack-path-aliases-in-phpstorm-when-using-laravel-mix
module.exports = {
output: { chunkFilename: 'js/[name].js?id=[chunkhash]' },
resolve: {
alias: {
'#': path.resolve('./resources/js'),
},
extensions: ['.js', '.vue', '.json'],
},
devServer: {
allowedHosts: 'all',
},
}
I have tried searching online but couldn't really find anything to help resolve the issue.
Thanks in advance.

Unexpected token error when using Vue-pdf

I'm creating an SPA with Laravel and Vue and am trying to use vue-pdf. I've successfully integrated several npm packages, but this one is giving me the error:
Uncaught SyntaxError: Unexpected token '<'
When I click on the file (worker.js) in my console, it looks like it's trying to perform a get request for a regular page on my site instead of grabbing the javascript so my hunch is that webpack isn't correctly transpiling vue-pdf. My current webpack config is:
const path = require('path')
const fs = require('fs-extra')
const mix = require('laravel-mix')
require('laravel-mix-versionhash')
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
mix
.js('resources/js/app.js', 'public/dist/js')
.sass('resources/sass/app.scss', 'public/dist/css')
.sass('resources/sass/flowy.scss', 'public/dist/css')
mix.babel([
'resources/js/helpers/Date.js',
'resources/js/helpers/LoginRedirect.js'
], 'public/assets/js/combined.js')
.disableNotifications()
if (mix.inProduction()) {
mix
// .extract()
// .version()
.versionHash()
} else {
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(() => publishAseets())
}
})
function publishAseets () {
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'))
}
Any help would be appreciated.

how to run vue app in the same domain with laravel sanctum for SPA

I need help in running my Vue spa in the same domain as my laravel app , when running "npm run serve" in terminal I think it's working but when I go to the browser it's refusing connection. I haven't done the backend which I will use sanctum for handling API. Has anybody here have the same project working on like me? love to make conversations to solve this.
Thanks in advance
here is the vue.config.js file
const path = require('path')
const webpack = require('webpack')
const createThemeColorReplacerPlugin = require('./config/plugin.config')
function resolve (dir) {
return path.join(__dirname, dir)
}
/**
* check production or preview(pro.loacg.com only)
* #returns {boolean}
*/
function isProd () {
return process.env.NODE_ENV === 'production'
}
const assetsCDN = {
css: [],
// https://unpkg.com/browse/vue#2.6.10/
js: [
'//cdn.jsdelivr.net/npm/vue#2.6.10/dist/vue.min.js',
'//cdn.jsdelivr.net/npm/vue-router#3.1.3/dist/vue-router.min.js',
'//cdn.jsdelivr.net/npm/vuex#3.1.1/dist/vuex.min.js',
'//cdn.jsdelivr.net/npm/axios#0.19.0/dist/axios.min.js'
]
}
// webpack build externals
const prodExternals = {
vue: 'Vue',
'vue-router': 'VueRouter',
vuex: 'Vuex',
axios: 'axios'
}
// vue.config.js
const vueConfig = {
configureWebpack: {
// webpack plugins
plugins: [
// Ignore all locale files of moment.js
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
],
// if prod is on, add externals
externals: isProd() ? prodExternals : {}
},
chainWebpack: (config) => {
config.resolve.alias
.set('#$', resolve('src'))
const svgRule = config.module.rule('svg')
svgRule.uses.clear()
svgRule
.oneOf('inline')
.resourceQuery(/inline/)
.use('vue-svg-icon-loader')
.loader('vue-svg-icon-loader')
.end()
.end()
.oneOf('external')
.use('file-loader')
.loader('file-loader')
.options({
name: 'assets/[name].[hash:8].[ext]'
})
// if prod is on
// assets require on cdn
if (isProd()) {
config.plugin('html').tap(args => {
args[0].cdn = assetsCDN
return args
})
}
},
css: {
loaderOptions: {
less: {
modifyVars: {
// less vars,customize ant design theme
'primary-color': '#00B4E4',
// 'link-color': '#F5222D',
'border-radius-base': '4px'
},
javascriptEnabled: true
}
}
},
}
if (process.env.VUE_APP_PREVIEW === 'true') {
vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
}
module.exports = vueConfig
module.exports = {
devServer: {
host: 'app.paymate-ui.test'
}
}
If I understand you correctly, you want to use Laravel and Vue.js together in the same application folder?
Should be pretty easy then.
First off, build your application with Vue scaffolding for the frontend.
Then, make a route that redirects everything to a single controller method that returns a spa view. (Or use a closure)
In this view, include your app.js as an asset and include the main Vue component (something like <app></app>).
Then build your Vue app. All requests will now be forwarded to the spa view, which includes your app.js, which should bootstrap Vue.

Nuxt.js app deployed to Heroku only has TailwindCSS's styles for < SM breakpoint

I deployed my 1st Nuxt.js app to Heroku...Everything went smooth but when I opened the app I realised that every .vue file/component has TailwindCSS styles up untill SM breakpoint. Mobile view is fine, but anything bigger than SM breakpoint is not apllied. I also used Purgecss to remove unused styles but not sure if that can cause the problems... Any ideas on how to fix this?
I fixed my problem just by finding this https://github.com/nuxt/nuxt.js/issues/2262
I created modules folder and added import-tailwind-config.js with the code:
module.exports = function () {
const tailwindConfig = require('#nuxtjs/tailwindcss')
this.options.env.tailwind = tailwindConfig
}
And inside nuxt.config.js, outside of module.exports I added
const PurgecssPlugin = require('purgecss-webpack-plugin')
const glob = require('glob-all')
const path = require('path')
class TailwindExtractor {
static extract (content) {
return content.match(/[A-z0-9-:/]+/g) || []
}
}
As well as this code inside of module.exports
build: {
extend (config, ctx) {
config.plugins.push(
new PurgecssPlugin({
whitelist: ['html', 'body'],
paths: glob.sync([
path.join(__dirname, 'components/**/*.vue'),
path.join(__dirname, 'layouts/**/*.vue'),
path.join(__dirname, 'pages/**/*.vue'),
path.join(__dirname, 'plugins/**/*.vue')
]),
extractors: [{
extractor: TailwindExtractor,
extensions: ['html', 'js', 'vue']
}]
})
)
}
}
modules: [
'~modules/import-tailwind-config'
]

Elixir gulp versioning - allow rev-manifest.js merges instead of ovewrites

I am attempting a way to run gulp for every page separately.
Every page has its gulp file and you can gulp for a page only with $ gulp --file=name
These gulpfiles are stored under /gulp So my main gulpfile.js has the following:
require('./gulp/elixir-extensions');
var args = require("yargs");
var file = args.argv.file;
if(file){
var path = './gulp/'+file;
require('./gulp/'+file);
}
else{
console.log('Pass the file: gulp --file:name');
}
So in my /gulp directory I have gulpfile extensions for every page on my site. home.js, about.js, contact.js, login.js etc..
Typically - home.js
var elixir = require('laravel-elixir');
elixir(function(mix) {
mix
/**
* Combine home scripts
*/
.scripts(...)
/**
* Combine home CSS files
*/
.styles(...)
/**
* Remove unused css selectors
*/
.uncss(...)
/**
* Remove redundant/repeated css declarations
*/
.purge(...)
/**
* Apply version control
*/
.version([
"public/css/home.css",
"public/js/home.js",
]);
});
and my gulp/elixir-extensions.js :
const gulp = require('gulp');
const Elixir = require('laravel-elixir');
const Task = Elixir.Task;
const uncss = require('gulp-uncss');
const purge = require('gulp-css-purge');
const rename = require('gulp-rename');
Elixir.extend('uncss', function(file, link, out, renamed) {
new Task('uncss', function() {
return gulp.src(file)
.pipe(uncss({
html: [link]
}))
.pipe(rename(renamed))
.pipe(gulp.dest(out));
});
});
Elixir.extend('purge', function(css, out, renamed) {
new Task('purge', function() {
return gulp.src(css)
.pipe(purge())
.pipe(rename(renamed))
.pipe(gulp.dest(out));
});
});
My problem is that the public/build/rev-manifest.js gets ovewritten every time I gulp for a single page.
rev-manifest.js after $ gulp --file=home
{
"css/home.css": "css/home-0a3d3926fc.css",
"js/home.js": "js/home-6df29810e8.js"
}
rev-manifest.js after $ gulp --file=about
{
"css/about.css": "css/about-fc0a5d3926.css",
"js/about.js": "js/about-f0921ds0e8.js"
}
How can I merge every revision like the following?
{
"css/home.css": "css/home-0a3d3926fc.css",
"js/home.js": "js/home-6df29810e8.js",
"css/about.css": "css/about-fc0a5d3926.css",
"js/about.js": "js/about-f0921ds0e8.js"
}
Figured out a solution - do all the versioning in the main gulpfile.js.
This way, every page gets its assets only versioned (but not compiled) every time.
require('./gulp/elixir-extensions');
var elixir = require('laravel-elixir');
var args = require("yargs");
var file = args.argv.file;
if(file){
var filepath = './gulp/'+file;
require('./gulp/'+file);
elixir(function(mix) {
mix
/**
* Apply version control to all assets
*/
.version([
"public/css/auth.css",
"public/css/backend.css",
"public/js/backend.js",
"public/css/home.css",
"public/js/home.js",
"public/css/about.css",
"public/js/about.js",
])
// .phpUnit()
// .compressHtml()
});
}
else{
console.log('Pass the file: gulp --file:name');
}

Resources