I am trying to load Bootstrap Vue into a Laravel 5.6 project
The official docs say to modify your webpack.config.js file like:
+ module: {
+ rules: [
+ {
+ test: /\.css$/,
+ use: [
+ 'style-loader',
+ 'css-loader'
+ ]
+ }
+ ]
+ }
Webpack docs: https://webpack.js.org/guides/asset-management/#loading-css
I don't have a webpack.config.js file so I tried loading the CSS in with Laravel mix
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
.styles('node_modules/bootstrap-vue/dist/bootstrap-vue.css', 'public/css');
This give me an error
mix.combine() requires a full output file path as the second argument.
and I'm not convinced it's the right way to do it.
What is the proper way to add bootstrap-vue into a new Laravel 5.6 project?
Import the Bootstrap Vue styles in your app.scss file directly, instead of through mix:
// app.scss
#import "~bootstrap/dist/css/bootstrap.css";
#import "~bootstrap-vue/dist/bootstrap-vue.css";
// webpack.mix.js
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
Laravel Mix already has the CSS loader configured so you don't need to set up a separate webpack.config.js file.
Related
I get the error Can't resolve '../api' when running npm run dev. I wrote a script to retrieve some data via an API call. This script works well when I put it in the vendor directory (vendor/badaso/core/src/js/api/modules). It is called by a store in resources/js/badaso/stores with
import api from "../../../../vendor/badaso/core/src/resources/js/api";
When I move this script to resources/js/badaso/api/modules and call it by...
import "../api"
Running "npm run dev", I get the following error.
Can't resolve '../api`
webpack.mix.js
const mix = require('laravel-mix');
//mix.js('resources/js/app.js', 'public/js') // original
mix.js('resources/js/*.js', 'public/js') // try -> same error
.postCss('resources/css/app.css', 'public/css', [
//
]);
// Can't resolve '../api'
// Badaso
mix.js("vendor/badaso/core/src/resources/js/app.js",
"public/js/badaso.js")
.sass("vendor/badaso/core/src/resources/js/assets/scss/style.scss",
"public/css/badaso.css")
.vue()`
I try this in webpack.mix.js
//mix.js('resources/js/app.js', 'public/js') // original
mix.js('resources/js/*.js', 'public/js') // try -> same error``
I built a single page application (SPA) using Laravel 8 + Vue.js + InertiaJs. Everything is working fine in the development environment, but when I compile assets for production, it shows me a blank page, and there is no error in the console. All assets are loading correctly with a 200 code, and everything seems to be OK, but the Vue app is not mounting!
webpack.mix.js
const mix = require('laravel-mix');
require('laravel-mix-workbox');
mix.webpackConfig({
output: {
filename: '[name].js',
chunkFilename: 'js/[name].js',
}
}).js('resources/js/app.js', 'public/js')
.extract(['vue'])
.version();
Image1
Image2
Image3
try using the inertiajs webpack.mix.js provided by the pingCRM github:
const path = require('path')
const mix = require('laravel-mix')
const cssImport = require('postcss-import')
const cssNesting = require('postcss-nesting')
/*
|--------------------------------------------------------------------------
| 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()
.postCss('resources/css/app.css', 'public/css', [
// prettier-ignore
cssImport(),
cssNesting(),
require('tailwindcss'),
])
.webpackConfig({
output: { chunkFilename: 'js/[name].js?id=[chunkhash]' },
resolve: {
alias: {
vue$: 'vue/dist/vue.runtime.esm.js',
'#': path.resolve('resources/js'),
},
},
})
.version()
.sourceMaps()
note you may have to follow the instructions for setting up tailwindcss which can be found here, only do this if you plan to use it otherwise remove the require('tailwindcss'), from the webpack file
you also may need to npm install --save-dev postcss-import and npm install --save-dev postcss-nesting the --save-dev flag will add it to your package.json file for future reference
I need to make sourceMaps for my mix.combine() assets but laravel mix only creates maps for default mix.js()
Code
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css').sourceMaps();
// admin
mix.styles([
'public/themes/admin/vendor/fontawesome-free/css/all.min.css',
'public/themes/admin/vendor/datatables/datatables.min.css',
'public/css/print.min.css',
'public/js/dist/summernote-bs4.css',
'public/themes/admin/css/admin.min.css'
], 'public/css/admin.css');
mix.combine([
'public/themes/admin/vendor/jquery/jquery.min.js',
'public/themes/admin/vendor/datatables/datatables.min.js',
'public/js/print.min.js',
'public/themes/admin/vendor/bootstrap/js/bootstrap.bundle.min.js',
'public/themes/admin/vendor/jquery-easing/jquery.easing.min.js',
'public/themes/admin/js/demo/datatables-demo.js',
'public/themes/admin/js/admin.min.js'
], 'public/js/admin.js').sourceMaps();
// front
mix.styles([
'public/themes/front/css/bootstrap.min.css',
'public/themes/front/css/mega-menu/mega_menu.css',
'public/themes/admin/vendor/fontawesome-free/css/all.min.css',
'public/themes/front/css/themify-icons.css',
'public/themes/front/css/magnific-popup/magnific-popup.css',
'public/themes/front/css/owl-carousel/owl.carousel.css',
'public/themes/front/revolution/css/settings.css',
'public/themes/front/css/slick/slick.css',
'public/themes/front/css/slick/slick-theme.css',
'public/themes/front/css/style.css',
'public/themes/front/css/responsive.css',
], 'public/css/front.css');
mix.combine([
'public/themes/front/js/jquery.min.js',
'public/themes/front/js/popper.min.js',
'public/themes/front/js/bootstrap.min.js',
'public/themes/front/js/mega-menu/mega_menu.js',
'public/themes/front/js/owl-carousel/owl.carousel.min.js',
'public/themes/front/js/slick/slick.min.js',
'public/themes/front/js/magnific-popup/jquery.magnific-popup.min.js',
'public/themes/front/js/isotope/isotope.pkgd.min.js',
'public/themes/front/js/jquery.appear.js',
'public/themes/front/js/counter/jquery.countTo.js',
'public/themes/front/revolution/js/jquery.themepunch.tools.min.js',
'public/themes/front/revolution/js/jquery.themepunch.revolution.min.js',
'public/themes/front/revolution/js/extensions/revolution.extension.actions.min.js',
'public/themes/front/revolution/js/extensions/revolution.extension.carousel.min.js',
'public/themes/front/revolution/js/extensions/revolution.extension.kenburn.min.js',
'public/themes/front/revolution/js/extensions/revolution.extension.layeranimation.min.js',
'public/themes/front/revolution/js/extensions/revolution.extension.migration.min.js',
'public/themes/front/revolution/js/extensions/revolution.extension.navigation.min.js',
'public/themes/front/revolution/js/extensions/revolution.extension.parallax.min.js',
'public/themes/front/revolution/js/extensions/revolution.extension.slideanims.min.js',
'public/themes/front/revolution/js/extensions/revolution.extension.video.min.js',
'public/themes/front/js/custom.js',
], 'public/js/front.js').sourceMaps();
result
/css/app.css
/js/app.js
/js/app.js.map <-- only app.js has map file
\css\admin.css
\css\front.css
\js\admin.js
\js\front.js <-- front.js didn't create map file
Any idea?
I am using vuejs in Laravel 5.7 to build an SPA. I am using mocha-webpack and vue-test-utils to write some vue component tests.
The tests can't seem to work out stylesheet imports into components. For example: I have a ExampleComponent.vue which includes the following:
</script>
<style lang="scss" scoped>
#import '#/_variables.scss';
.subpanel-control > ul > li {
background-color: lighten($body-bg, 50);
margin-left: 10px;
height: 25px;
width: 25px;
line-height: 25px;
color: $body-bg;
}
when running npm run test I get the following error:
Error in ./resources/assets/js/components/Panel.vue?vue&type=style&index=0&id=21f01f46&lang=scss&scoped=true&
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
#import '#/variables';
^
Can't find stylesheet to import.
╷
98 │ #import '#/variables';
│ ^^^^^^^^^^^^^
╵
stdin 98:9 root stylesheet
in C:\Users\jjackson\Documents\projects\wave\resources\assets\js\components\Panel.vue (line 98, column 9)
I can't work out why it doesn't understand the alias #. Here is my webpack.mix.js:
let mix = require('laravel-mix');
const path = require('path');
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
.sass('resources/assets/sass/nifty.scss', 'public/css', {
implementation: require('node-sass')
})
.sass('resources/assets/sass/themes/type-b/theme-ocean.scss', 'public/css')
.less('resources/assets/less/bootstrap-4-utilities.less', 'public/css')
.webpackConfig({
resolve: {
alias: {
'#': path.resolve('resources/assets/sass'),
'~': path.resolve('resources/assets/js')
}
}
})
.sourceMaps();
if (mix.inProduction()) {
mix.version();
}
Any help would be appreciated
While struggling with the same issue I landed on this page - https://github.com/vuejs/vue-cli/issues/4053 and a comment from robbishop that lead me to my solution.
Using the above I managed to find a configuration in webpack.mix.js that seem to work:
First install null-loader (npm i -D null-loader)
Add the following line in rules:
{ test: /\.scss$/, use: [{ loader: 'null-loader' }] }
My webpack.mix.js looks like that:
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| 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')
.webpackConfig({
module: {
rules: [
{ test: /\.scss$/, use: [{ loader: 'null-loader' }] }
]
},
resolve: {
alias: {
'#': path.resolve('somepath/sass')
}
}
})
.sass('some/path/app.scss', 'some/path/css');
My unit tests are now executed while having scss imports in my components.
This turned out to be a docker problem. Was trying to run npm run dev outside of the docker environment, and it was causing this error. When I ran all npm commands inside of the container everything worked fine
I'm using Laravel 5.6, Laravel Mix 2.0, and Bootstrap-Vue 2.0.0-rc.1.
Trying to find a way to configure Laravel Mix to include Bootstrap-Vue's CSS into my app.css file and prevent Bootstrap-Vue from including <style> tags into the page <head>.
I saw this note in the package docs but still not sure how to use this properly:
Note: requires webpack configuration to load css files (official guide)
Finally, found a solution - ExtractTextPlugin.
let mix = require('laravel-mix');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
mix.webpackConfig({
module: {
rules: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
}
]
}
});
Reference: https://github.com/JeffreyWay/laravel-mix/issues/1589
Install:
npm i bootstrap-vue
npm install --save-dev style-loader css-loader
Use:
edit resources/js/app.js to:
import Vue from 'vue'
import BootstrapVue from 'bootstrap-vue'
Vue.use(BootstrapVue)
edit resources/sass/app.scss to:
Import the styles:
import '~bootstrap/dist/css/bootstrap.css'
import '~bootstrap-vue/dist/bootstrap-vue.css'
Make sure the app.js and app.css are included in the blade(view) that is acting as the container for your vue.
See: https://bootstrap-vue.js.org/docs/