I am confused how to change sass-loader settings using vue.config in this documentation there is a webpack.config but my project doesn't have one and I don't think I should have one because according to this documentation I should use vue.config.
The command vue inspect contains the string loader: 'sass-loader', 8 times so I'm not sure what to change.
My source code is the following:
<style lang="scss">
.some-class {
border-bottom: 100px solid $alert;
}
</style>
Then I would like to adjust the values for webpack using vue.config to:
{
loader: 'sass-loader',
options: {
prependData: '$alert: ' + process.env.ALERT_COLOR + ';',
}
}
I suspect I have to change the following entry (coming from vue inspect):
/* config.module.rule('scss').oneOf('vue-modules') */
{
resourceQuery: /module/,
use: [
{
loader: 'vue-style-loader',
options: {
sourceMap: false,
shadowMode: false
}
},
{
loader: 'css-loader',
options: {
sourceMap: false,
importLoaders: 2,
modules: true,
localIdentName: '[name]_[local]_[hash:base64:5]'
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: false
}
},
{
loader: 'sass-loader',
options: {
sourceMap: false,
implementation: {
run_: function() {
return _call(f, Array.prototype.slice.apply(arguments));
},
render: function() {
return _call(f, Array.prototype.slice.apply(arguments));
},
renderSync: function() {
return _call(f, Array.prototype.slice.apply(arguments));
},
info: 'dart-sass\t1.23.0\t(Sass Compiler)\t[Dart]\ndart2js\t2.5.1\t(Dart Compiler)\t[Dart]',
types: {
Boolean: function() {
return _call(f, Array.prototype.slice.apply(arguments));
},
Color: function() {
return _call(f, this, Array.prototype.slice.apply(arguments));
},
List: function() {
return _call(f, this, Array.prototype.slice.apply(arguments));
},
Map: function() {
return _call(f, this, Array.prototype.slice.apply(arguments));
},
Null: function() {
return _call(f, Array.prototype.slice.apply(arguments));
},
Number: function() {
return _call(f, this, Array.prototype.slice.apply(arguments));
},
String: function() {
return _call(f, this, Array.prototype.slice.apply(arguments));
},
Error: function Error() { [native code] }
}
}
}
}
]
}
Reading through the docs you linked I would guess it's something like this:
vue.config.js
module.exports = {
chainWebpack: config => {
const cssRule = config.module.rule('css')
// clear all existing loaders.
// if you don't do this, the loader below will be appended to
// existing loaders of the rule.
cssRule.uses.clear()
// add replacement loader(s)
cssRule
.use('sass-loader')
.loader('sass-loader')
.tap(options => {
// modify the options...
return options
})
}
}
And add the sass options you want were is says modify the options.
It's worth noting that cssRule.uses.clear() will clear the previous CSS rules. Which I think you will need to do otherwise you might have conflicting rules. If you find that it is removing a rule you need, I would add it back manually (the same way you are adding sass.
The following seems to work, in my vue.config
const path = require('path');
module.exports = {
css: {
loaderOptions: {
sass: {
data: `
#import "Theme/_colors.scss";
`,
},
},
},
configureWebpack: {
resolve: {
alias: {
Theme: path.resolve(
__dirname,
`src/themes/${process.env.THEME || 'light'}/`
),
},
},
},
};
In _colors.css I can just set the variables: $alert:red;
Related
I write Vue2 app using Vuetify2. I need to add sass-loader to webpack as per docs: https://vuetifyjs.com/en/getting-started/installation/#webpack-install
So I need to edit webpack and want to do this using chainWebpack. According to docs I can do it in vue.config.js. The issue is that I don't know how to properly 'convert' regular webpack snippet to chaining. I need to chain this:
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.s(c|a)ss$/,
use: [
'vue-style-loader',
'css-loader',
{
loader: 'sass-loader',
// Requires sass-loader#^7.0.0
options: {
implementation: require('sass'),
indentedSyntax: true // optional
},
// Requires >= sass-loader#^8.0.0
options: {
implementation: require('sass'),
sassOptions: {
indentedSyntax: true // optional
},
},
},
],
},
],
}
}
and this is my vue.config.js file where I tried to use chainWebpack (note that transpileDependencies was in this file before, I don't touch it and it must be here):
const { defineConfig } = require('#vue/cli-service')
module.exports = defineConfig({
transpileDependencies: [
'vuetify'
],
chainWebpack: config => {
config.module
.rule('sass')
.test(/\.s(c|a)ss$/)
.use('vue-style-loader','css-loader',)
.loader('sass-loader')
.tap(options => {
implementation: require('sass'),
sassOptions: {
indentedSyntax: true // optional
}
return options
})
}
})
However it doesn't work.
I want give an element a class when it's in the viewport and I don't know how I can handle it. I watched a few Videos on Youtube but nothing helped me.
I work with a boilerplate so I can't implement additional plugins.
My script looks actually like this.
export default {
head() {
return {
title: this.$t("headData.index.title"),
meta: [
{
hid: "description",
name: "description",
content: this.$t("headData.index.description")
}
]
}
},
data() {
return {
debugSingleScroll: true,
}
},
methods: {
handleScroll() {
if(this.debugSingleScroll) {
this.scrollToNextModule()
this.scrollToLastModule()
this.debugSingleScroll = false;
}
},
scrollToNextModule() {
this.$refs.factsModule.triggerAnimation();
},
scrollToLastModule() {
},
},
mounted () {
window.addEventListener('scroll', this.handleScroll);
},
destroyed () {
window.removeEventListener('scroll', this.handleScroll);
},
}
I have been trying to use Dialog box for authentication. The dialog box is opening but not sending back message via messageParent API, however there is not problem when displayInIframe is added to dialog properties. But we cannot use Iframe for authentication.
Here is the function calling dialog,
function openDialog() {
console.log("openDialog");
Office.context.ui.displayDialogAsync("https://localhost:3000/src/auth/auth.html ", { height: 50, width: 50, promptBeforeOpen: false }, dialogCallback);
}
A part of web.config file
module.exports = async(env, options) => {
const dev = options.mode === "development";
const config = {
devtool: "source-map",
entry: {
polyfill: "#babel/polyfill",
taskpane: "./src/taskpane/taskpane.js",
commands: "./src/commands/commands.js",
auth: "./src/auth/auth.js"
},
resolve: {
extensions: [".ts", ".tsx", ".html", ".js"]
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["#babel/preset-env"]
}
}
},
{
test: /\.html$/,
exclude: /node_modules/,
use: "html-loader"
},
{
test: /\.(png|jpg|jpeg|gif)$/,
use: "file-loader"
}
]
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
filename: "taskpane.html",
template: "./src/taskpane/taskpane.html",
chunks: ["polyfill", "taskpane"]
}),
new CopyWebpackPlugin([{
to: "taskpane.css",
from: "./src/taskpane/taskpane.css"
}]),
new HtmlWebpackPlugin({
filename: "commands.html",
template: "./src/commands/commands.html",
chunks: ["polyfill", "commands"]
}),
new HtmlWebpackPlugin({
filename: "auth.html",
template: "./src/auth/auth.html",
chunks: ["polyfill", "dialog"]
}),
],
devServer: {
headers: {
"Access-Control-Allow-Origin": "*"
},
https: (options.https !== undefined) ? options.https : await devCerts.getHttpsServerOptions(),
port: process.env.npm_package_config_dev_server_port || 3000
}
};
Here is the simple auth.js file I am using for debugging,
Office.initialize = function() {
$('#button1').click(one);
};
function one() {
console.log("picked 1");
Office.context.ui.messageParent("Picked 1");
console.log("picked");
// Both the console lines are working in new window but messageParent not returning message
}
i'm trying to activate sourcemaps for everything on my cli3 project.
so far i have
vue.config.js
module.exports = {
css: {
loaderOptions: {
css: {
sourceMap: true
},
sass: {
sourceMap: true
},
stylus: {
sourceMap: true
},
postcss: {
sourceMap: true
}
}
},
devServer: { port: 8888 },
configureWebpack: {
devtool: 'cheap-module-eval-source-map',
// ...
according to this https://cli.vuejs.org/config/#css-sourcemap, there is no more option except less (which i don't use).
now vue inspect gives me:
{
loader: 'vue-style-loader',
options: {
sourceMap: false,
shadowMode: false
}
},
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 2
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
implementation: {
run_: function() {
return _call(f, Array.prototype.slice.apply(arguments));
},
render: function() {
return _call(f, Array.prototype.slice.apply(arguments));
},
renderSync: function() {
return _call(f, Array.prototype.slice.apply(arguments));
},
info: 'dart-sass\t1.22.9\t(Sass Compiler)\t[Dart]\ndart2js\t2.4.0\t(Dart Compiler)\t[Dart]',
types: {
Boolean: function() {
return _call(f, Array.prototype.slice.apply(arguments));
},
Color: function() {
return _call(f, this, Array.prototype.slice.apply(arguments));
},
List: function() {
return _call(f, this, Array.prototype.slice.apply(arguments));
},
Map: function() {
return _call(f, this, Array.prototype.slice.apply(arguments));
},
Null: function() {
return _call(f, Array.prototype.slice.apply(arguments));
},
Number: function() {
return _call(f, this, Array.prototype.slice.apply(arguments));
},
String: function() {
return _call(f, this, Array.prototype.slice.apply(arguments));
},
Error: function Error() { [native code] }
}
},
indentedSyntax: true
}
how can I activate sourcemaps for vue component styles? also, configurewebpack.devtool seems to have no effect at all. (or does it only have an effect when paired with loaderOptions?)
thanks :)
Should be:
module.exports = {
css: {sourceMap: true},
To fix all issues with vue css-sourcemaps, see Vue CLI sourcemaps to style part of vue component file
I know that it involves modifying vue.config.js, but simply pasting my desired config in the configureWebpack object doesn't seem to work. Has anyone else been able to figure this out?
Desired config to add:
module: {
rules: [
{
test: /\.vue$/,
use: [
{
loader: "vue-loader",
options: {
loaders: {
stylus: [
{
loader: "stylus-resources-loader",
options: {
resources:
"./src/assets/_base.styl",
},
},
],
},
},
},
],
},
],
},
Thank you!
const path = require('path');
module.exports = {
chainWebpack: (config) => {
config.module
.rule('vue')
.use('vue-loader')
.tap((options) => {
options.loaders.stylus = options.loaders.stylus.concat({
loader: 'stylus-resources-loader',
options: {
resources: path.resolve('./src/assets/_base.styl'),
},
});
return options;
});
},
};
UPDATE:
It should be noted that the value of the lang attribute in <style lang="stylus"> will affect the way the configuration item is written!
When lang is stylus, the stylus are mounted on loader, which should be written like this: options.loaders.stylus, and when the value of lang is styl, It should be written as options.loaders.styl.
Because of the following code in #vue/cli-service/lib/webpack/CSSLoaderResolver.js:
getLoader (test, loader, options = {}) {
styl (test = /\.styl$/) {
return this.getLoader(test, 'stylus')
}
stylus (test = /\.stylus$/) {
return this.getLoader(test, 'stylus')
}
}
refer to https://stackoverflow.com/a/49086022/4723163