Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility With Laravel Mix? #49

Closed
codeitlikemiley opened this issue Apr 26, 2019 · 33 comments
Closed

Compatibility With Laravel Mix? #49

codeitlikemiley opened this issue Apr 26, 2019 · 33 comments

Comments

@codeitlikemiley
Copy link

Hi ived tried many times, using it with laravel mix, but i keep getting error...
I understand this one is build to be used for vue-cli 3, yeah it works with nuxt also
but in case of laravel mix, how can use it on it, hope someone can help me with it thanks

@lukadriel7
Copy link

Hello, This implementation seems to work but weirdly I cannot read icon fonts with it (mdi).
I post here so that someone may improve on it.

const mix = require('laravel-mix');

mix.extend('vuetify', new class {
    webpackRules(){
        return [
            {
                type: 'javascript/auto',
                loader: 'vuetify-loader'
            }
        ]
    }
})

mix.vuetify().js('resources/js/app.js', 'public/js').sass('resources/sass/app.scss', 'public/css')

@codeitlikemiley
Copy link
Author

let me check on it, and see how i can add the mdi icon fonts thanks for the share

@likeadeckofcards
Copy link

@codeitlikemiley Did you get this working?

@lukadriel7 I get an issue app.js Uncaught ReferenceError: component is not defined

@codeitlikemiley
Copy link
Author

I made a package
https://packagist.org/packages/codeitlikemiley/vuetified-laravel-preset
This work only because Dynamic components comes into play...
i dont even need to do The OP , cause it wont really work and faulty...
if u installed my package be sure to try it on fresh laravel install cause this is a preset.
also if u are using windows, make sure u use bash to run the command and have python installed inside your bash env.

@avengerweb

This comment has been minimized.

@imkonsowa

This comment has been minimized.

@KaelWD
Copy link
Member

KaelWD commented Aug 7, 2019

See laravel-mix/laravel-mix#2173 and my comment on discord.

If you want my personal opinion: use vue-cli instead. It's better supported, easier to use, and has sane defaults.

@leninsheikh
Copy link

use vuetify-loader in laravel mix like this

webpack.config.js

const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');
module.exports = {
    plugins: [
        new VuetifyLoaderPlugin(),
    ]
};

webpack.mix.config

const mix = require('laravel-mix');
const webpack = require('./webpack.config');

mix.js('resources/frontend/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .webpackConfig(Object.assign(webpack));

@BraunLukas
Copy link

@leninsheikh

trying to use your configuration, but it still give me some problems

Error: [VuetifyLoaderPlugin Error] No matching rule for vue-loader found.

when adding rules the js compiles, but im gettin JS errors on site loading
[Vue warn]: Unknown custom element: <v-layout> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

@nekosaur
Copy link
Member

You can compare your setup with this example project https://github.com/nekosaur/laravel-vuetify

@pintoflager
Copy link

@nekosaur 's example project is a working example as long as you don't update sass-loader.
To be honest I'm just learning here and not 100% sure what's going on but if you do:

  1. npm remove sass-loader
  2. npm install sass-loader
  3. npm run rev
    Result is errors in vuetify main.scss file and fail in compile.

After npm install sass-loader@^7.1.0 -D I get following version installed in my package.json "sass-loader": "^7.3.1", and everything works fine again.

@beerwin
Copy link

beerwin commented Oct 26, 2019

use vuetify-loader in laravel mix like this

webpack.config.js

const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');
module.exports = {
    plugins: [
        new VuetifyLoaderPlugin(),
    ]
};

webpack.mix.config

const mix = require('laravel-mix');
const webpack = require('./webpack.config');

mix.js('resources/frontend/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .webpackConfig(Object.assign(webpack));

This should be put in the documentation. It just works.

@pintoflager
Copy link

No need for separate webpack.config.js
Laravel mix seem to have .webpackConfig where you can add vuetifyloader

const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .webpackConfig({
        plugins: [
            new VuetifyLoaderPlugin({
                options: {}
            }),
        ]
    })
    .version()
    .sourceMaps()

@jinxkitt108

This comment has been minimized.

@tomcoonen
Copy link

tomcoonen commented Nov 25, 2019

I can't get the VuetifyLoaderPlugin to work, keep getting this error i.c.m. Laravel Mix:
Error: [VuetifyLoaderPlugin Error] No matching rule for vue-loader found. Make sure there is at least one root-level rule that uses vue-loader.

I've tried the mix.extend but that gives me the same issues.

Vue CLI 3 / Laravel Mix 5.

Any ideas?

@DRoet
Copy link
Contributor

DRoet commented Nov 25, 2019

@tomcoonen could you provide a small repro?

cli 4.0.5 + loader 1.4.2 works fine for me, so it could be related to your specific setup

@tomcoonen
Copy link

@DRoet I'm going to see if I can reproduce it in some way

@aubreychiduku
Copy link

I can't get the VuetifyLoaderPlugin to work, keep getting this error i.c.m. Laravel Mix:
Error: [VuetifyLoaderPlugin Error] No matching rule for vue-loader found. Make sure there is at least one root-level rule that uses vue-loader.

I've tried the mix.extend but that gives me the same issues.

Vue CLI 3 / Laravel Mix 5.

Any ideas?

I'm having the same issue without Vue CLI but using Laravel Mix 5

where vuetify-loader 1.4.2 is included as a plugin using

.webpackConfig({ plugins: [new VuetifyLoaderPlugin()] })

@KaelWD
Copy link
Member

KaelWD commented Nov 25, 2019

What version of vue-loader do you have?

@jinxkitt108

This comment has been minimized.

@fraganzas
Copy link

Had the same issue when I updated to 1.4.2.
Running npm install vuetify-loader@1.4.1 fixed it for me.

@diorray
Copy link

diorray commented Nov 29, 2019

After several hours of trying, i've made it working seamlessly.

First, don't use 1.4.2, install 1.4.1 by npm install vuetify-loader@1.4.1
Then, here is working solution

const mix = require('laravel-mix');
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');

mix.options({
		extractVueStyles: true,
	}).webpackConfig({
		resolve: {
			extensions: ['.js', '.json', '.vue', '.css', '.scss', '.sass'],
			alias: {
				'~': path.join(__dirname, './resources/js'),
				'$comp': path.join(__dirname, './resources/js/components')
			}
		},
		module: {
			rules: [
				{
					test: /\.js$/,
					loader: 'babel-loader',
					exclude: /node_modules\/(?!(vuetify)\/)/,
				},
				{
					test: /\.(sc|c|a)ss$/,
					use: [
						'vue-style-loader',
						'css-loader',
						{
							loader: 'sass-loader',
							options: {
								implementation: require('sass'),
								sassOptions: {
									fiber: require('fibers'),
									indentedSyntax: true
								},
							},
						},
					]
				},
			]
		},
		plugins: [
			new VuetifyLoaderPlugin()
		]
	}).js('resources/js/app.js', 'public/js/app.js')
	.css('resources/css/app.css', 'public/css/');

Notes

  • You don't need to include vue-loader module or vue-loader rule as its already included in Laravel Mix, in fact if you try to do so, you will get these error below as you added module for the second time:

for including vue-loader module:

Error: [VueLoaderPlugin Error] No matching use for vue-loader is found.
Make sure the rule matching .vue files include vue-loader in its use.

for including vue-loader rule:
blank page + [Vue warn]: Failed to mount component: template or render function not defined. in browser console

@goldcoders
Copy link

@diorray can you share you package.json file also i didnt manage to it work on my end
must be about the dependencies has mismatch packages

@diorray
Copy link

diorray commented Dec 2, 2019

@diorray can you share you package.json file also i didnt manage to it work on my end
must be about the dependencies has mismatch packages

@goldcoders run this command:
npm install mini-css-extract-plugin fibers deepmerge css-loader resolve-url-loader sass sass-loader style-loader stylus stylus-loader vue vue-loader@^15.7.2 vue-template-compiler vuetify-loader@1.4.1 vuetify @babel/preset-env babel-plugin-transform-object-rest-spread babel-polyfill-D

If still doesnt work, tell us the errors you're getting

@goldcoders
Copy link

im getting this error

ERROR in ./node_modules/vuetify/src/components/VDataTable/VDataTableHeader.sass (./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/src??ref--7-3!./node_modules/sass-loader/dist/cjs.js??ref--7-4!./node_modules/vuetify/src/components/VDataTable/VDataTableHeader.sass)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
ValidationError: Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema.
 - options has an unknown property 'indentedSyntax'. These properties are valid:
   object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter? }
    at validate (/home/uriah/Sites/xxx/node_modules/sass-loader/node_modules/schema-utils/dist/validate.js:85:11)
    at Object.loader (/home/uriah/Sites/xxx/node_modules/sass-loader/dist/index.js:36:28)

@goldcoders
Copy link

Can you share a repo that has a minimimal install of vuetify working with vuetify loader
that has all .babelrc webpack.mix.js app.js etc.
i find it hard to make it work on my end using your suggestions

@diorray
Copy link

diorray commented Dec 3, 2019

Can you share a repo that has a minimimal install of vuetify working with vuetify loader
that has all .babelrc webpack.mix.js app.js etc.
i find it hard to make it work on my end using your suggestions

@goldcoders you should remove node-sass, run this commmand and build again: npm uninstall node-sass && npm install

@KaelWD KaelWD closed this as completed in 9fb6ec3 Dec 4, 2019
@SyncroIT
Copy link

SyncroIT commented Mar 11, 2020

No need for separate webpack.config.js
Laravel mix seem to have .webpackConfig where you can add vuetifyloader

const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .webpackConfig({
        plugins: [
            new VuetifyLoaderPlugin({
                options: {}
            }),
        ]
    })
    .version()
    .sourceMaps()

I tried to do so but I always get this error when using vuetify-loader, it doesn't matter which version I use (I even tried the 1.4.1 instead of the 1.4.3).

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined

PS: I'm using Laravel 5.6

@filipembcruz
Copy link

After many issues, I solve this on Laravel 8.

// Dependencies
{
        "laravel-mix": "^6.0.6",
        "sass": "^1.20.1",
        "sass-loader": "^8.0.0",
        "vue": "^2.5.17",
        "vue-loader": "^15.9.5",
        "vue-template-compiler": "^2.6.10",
        "vuetify": "^2.4.3",
        "vuetify-loader": "^1.7.1",
}
// webpack.mix.js
const mix = require('laravel-mix');
const webpack = require('./webpack.config');
Mix.listen('configReady', webpackConfig => {
    // scss
    const scssRule = webpackConfig.module.rules.find(
        rule =>
            String(rule.test) ===
            String(/\.scss$/)
    );
    scssRule.oneOf.forEach(o => {
        const scssOptions = o.use.find(l => l.loader === 'sass-loader').options
        scssOptions.prependData = '@import "./resources/sass/_variables.scss";'
    })

    // sass
    const sassRule = webpackConfig.module.rules.find(
        rule =>
            String(rule.test) ===
            String(/\.sass$/)
    );

    sassRule.oneOf.forEach(o => {
        const scssOptions = o.use.find(l => l.loader === 'sass-loader').options
        scssOptions.prependData = '@import "./resources/sass/_variables.scss"'
    })
})
mix.js('resources/js/app.js', 'public/js')
    .js('resources/js/gift.js', 'public/js')
    .vue()
    .sass('resources/sass/pages/home.scss', 'public/css')
    .sass('resources/sass/pages/gift.scss', 'public/css')
    .webpackConfig(Object.assign(webpack))
    .copyDirectory('resources/images/', 'public/images');

if (mix.inProduction()) {
    mix.version();
};
// webpack.config.js
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');
module.exports = {
    plugins: [
        new VuetifyLoaderPlugin(),
    ]
};

@JeffreyHosler
Copy link

@filipembcruz

I been working on this for like a month and kept telling myself i would come back later and fix it. This did the trick. thank you sir.

@JeffreyHosler
Copy link

actually @filipembcruz, do you happen to have a git i can look at? I am having issues with vuetify overwriting my custom css. Maybe its being loaded first or something.

It is loading my variables which is nice. And my css is showing up in in console.log, just being over ridden by vuetify.

// webpack.mix.js

Mix.listen('configReady', webpackConfig => {
    // scss
    const scssRule = webpackConfig.module.rules.find(
        rule =>
            String(rule.test) ===
            String(/\.scss$/)
	);
    scssRule.oneOf.forEach(o => {
        const scssOptions = o.use.find(l => l.loader === 'sass-loader').options
        scssOptions.additionalData = '@import "@/styles/variables.scss";'
    })

    // sass
    const sassRule = webpackConfig.module.rules.find(
        rule =>
            String(rule.test) ===
            String(/\.sass$/)
    );

    sassRule.oneOf.forEach(o => {
        const scssOptions = o.use.find(l => l.loader === 'sass-loader').options
        scssOptions.additionalData = '@import "@/styles/variables.scss"'
    })
})

mix.js('Resources/platform/src/main.js', path.resolve(__dirname, '../../public/assets/platform/js') )
	.vue()
	.webpackConfig({
		resolve: {
			alias: {
				'@webinar': path.resolve(__dirname, 'Resources'),
				'@assets': path.resolve(__dirname, 'Resources/platform/src/assets'),
				'@': path.resolve(__dirname, 'Resources/platform/src/'),
			}
		},
		output: {
			filename: '[name].js',
			path: path.resolve(__dirname, '../../public'),
			chunkFilename: mix.inProduction() ? 'assets/webinars/platform/js/[name].[chunkhash].js' : 'assets/webinars/platform/js/[name].js',
		},
		plugins: [
			new VuetifyLoaderPlugin(),
			new MomentLocalesPlugin({
				localesToKeep: ['el'],
			}),
		],
	})
	.sass('Resources/platform/src/styles/main.scss', path.resolve(__dirname, '../../public/assets/platform/css') )
// main.scss
@import 'variables';
@import 'mixins/breakpoints';
@import 'mixins/functions';
@import 'mixins/helpers';
@import 'mixins/mixins';
@import 'custom';

@import "components/header";
@import "components/form-ellements";
@import "components/login-form";
@import "components/sidebar";
@import "components/video-block";
@import "components/message-block";
@import "components/chat-block";
@import "components/faq-block";
@import "components/user-profile-box";
@import "components/empty-box";
@import "components/mobile-nav";
@import "components/overview-box";
@import "components/internet-users-popup";
@import "components/admin-panel";

.v-application {
  overflow: hidden;
  background: $primary-link-hover;
}

.header, .content{
  min-height: 100%;
  position: relative;
}

For example, this scss is howing up, but is getting over ridden by vuetifies scss

// components/login-form.scss
.login-form {
  .v-label {
    margin-bottom: 0;
    color: $primary-text-color;
    font-size: 14px;
    line-height: 1;
  }

  .v-btn__content {
    font-size: 15px;
    font-weight: 500;
  }

  a {
    &:hover {
      color:$primary-text-color;
    }
  }
}

@JeffreyHosler
Copy link

I fixed my issue by appending my custom css. like so

webpack.mix.js

Mix.listen('configReady', webpackConfig => {
    // scss
    const scssRule = webpackConfig.module.rules.find(
        rule =>
            String(rule.test) ===
            String(/\.scss$/)
    );
    scssRule.oneOf.forEach(o => {
        const scssOptions = o.use.find(l => l.loader === 'sass-loader').options
        scssOptions.additionalData = '@import "@/styles/main.scss";'
    })

    // sass
    const sassRule = webpackConfig.module.rules.find(
        rule =>
            String(rule.test) ===
            String(/\.sass$/)
    );

    sassRule.oneOf.forEach(o => {
        const scssOptions = o.use.find(l => l.loader === 'sass-loader').options
        scssOptions.additionalData = '@import "@/styles/main.scss"'
    })
})
// main.scss
@import 'variables';

.myCss {
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests