How to solve scss conflict between NuxtJS and Vuetify 2.0
You can use vuetify-module. The current version is 1.0.1
and is using vuetify v2
After you install this module you can check the vuetify
version with npm list vuetify
Using vuetify custom sass variables in a vue app using rails/webpacker
Thanks to the help of this GitHub comment, I've got it working.
The default loaders can be removed with environment.loaders.delete('sass') // same for 'moduleSass', 'moduleCss', 'css'
.
Then, they can be replaced by new ones. I've separated the scss and sass loaders to their own files:
// config/webpack/loaders/sass.js
const { config } = require('@rails/webpacker');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
test: /\.sass$/,
use: [
config.extract_css === false
? 'vue-style-loader'
: MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 2,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
implementation: require('sass'),
fiber: require('fibers'),
data: '@import "app/frontend/src/assets/styles/variables.scss"',
},
},
],
};
// config/webpack/loaders/scss.js
const { config } = require('@rails/webpacker');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
test: /\.scss$/,
use: [
config.extract_css === false
? 'vue-style-loader'
: MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 2,
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
implementation: require('sass'),
fiber: require('fibers'),
data: '@import "app/frontend/src/assets/styles/variables.scss";',
},
},
],
};
These re-implement the basic webpacker integrations with CSS extraction.
Then, I add them to the main config like so:
// config/webpack/environment.js
const { environment } = require('@rails/webpacker');
const path = require('path');
// Plugins
const { VueLoaderPlugin } = require('vue-loader');
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');
// Loaders
const erb = require('./loaders/erb');
const sass = require('./loaders/sass');
const scss = require('./loaders/scss');
const vue = require('./loaders/vue');
const yml = require('./loaders/yml');
// Remove webpacker's conflicting loaders
environment.loaders.delete('moduleSass');
environment.loaders.delete('moduleCss');
environment.loaders.delete('sass');
// Modify base css loader to support vue SFC style tags
environment.loaders.get('css').use.find((el) => el.loader === 'style-loader').loader = 'vue-style-loader';
// Apply plugins
environment.plugins.prepend('VuetifyLoaderPlugin', new VuetifyLoaderPlugin());
environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin());
// Apply custom loaders
environment.loaders.append('erb', erb);
environment.loaders.append('yml', yml);
environment.loaders.append('vue', vue);
environment.loaders.append('sass', sass);
environment.loaders.append('scss', scss);
// Shorthands for import statements
environment.config.resolve.alias = {
// Use the same vue package everywhere
vue: 'vue/dist/vue.esm',
// use '@' as absolute path from /src
'@': path.resolve(__dirname, '../../app/frontend/src/'),
};
module.exports = environment;
One important part here as well is where I still modify the default css-loader to use 'vue-style-loader' over 'style-loader'. But for larger changes (like vuetify) I'm able to define my own defined loaders for SASS / SCSS syntax.
Maybe it can be optimized further to remove the duplication, but as long as it's only two configurations, I'm just happy it works :)
I can't load configuration scss file in vuejs using sass-resources-loader
Eventually i created project from scratch using vue-cli@3
and added to vue.config.js this code:
const path = require('path');
module.exports = {
chainWebpack: config => {
const oneOfsMap = config.module.rule('scss').oneOfs.store
oneOfsMap.forEach(item => {
item
.use('sass-resources-loader')
.loader('sass-resources-loader')
.options({
resources: [
path.resolve(__dirname, './src/assets/scss/_variables.scss'),
path.resolve(__dirname, './src/assets/scss/_mixins.scss'),
]
})
.end()
})
}
}
Related Topics
Multiple Navbars on The Same Page with Twitter's Bootstrap 3
Neatly Display Images of Different Sizes Sequentially in The Same UI Element
Generating Vendor Prefixes in Less
Childrens Selectors from Sibling Parent Divs Using CSS for Hover Effect
How to Create Variable Columns and Fill Them Up
Website Will Not Scroll on Mobile Devices
Overlap Notification Badge on Glyph in Bootstrap 3
Sublime Text Wrap Selection with Snippet
Zoom in and Out on Mouse Click with CSS
How to Make Popup Look at The Centre of The Screen
Shiny Presentation (iOSlides): Custom CSS and Logo Windows 7/8
Flex-Basis for Wrapping Columns
CSS Animation, Fadein/Fadeout 2 Images Continuously
Remove The Bottom Margin of a Handsontable
A Mnemonic for The Order of CSS Margin and Padding Shorthand Properties