My main JS has the following code -
/*global require*/
'use strict';
require.config({
shim: {
backbone:{
deps:[
'underscore',
'jquery'
],
exports: 'Backbone'
},
bootstrap:{deps:['jquery']},
},
paths: {
jquery: '../bower_components/jquery/dist/jquery',
backbone: '../bower_components/backbone/backbone',
underscore: '../bower_components/underscore/underscore',
bootstrap: '../bower_components/bootstrap/dist/js/bootstrap',
text:'../bower_components/requirejs-text/text',
router: 'routes/router'
}
});
require([
'jquery',
'underscore',
'backbone',
'bootstrap',
'router'
//'text!bootstrapCSS'
], function ($, _, Backbone, undefined, mainRouter) {
var router = new mainRouter();
Backbone.history.start();
});
and view.home.js has the following code
define(
[
'jquery',
'underscore',
'backbone',
'bootstrap',
'text!templates/header.html',
'text!/bower_components/bootstrap/dist/css/bootstrap.css'
],
function($, _, Backbone, undefined, header, bootstrapCSS){
var HomeView = Backbone.View.extend({
el: '.header-container',
headerTemplate: _.template(header),
initialize: function(){
console.log("in view-home initialize")
this.render();
},
render: function(){
console.log("render header");
this.$el.html(this.headerTemplate());
console.log("render header complete i guess");
},
events: {},
});
return HomeView;
})
the above code is being used to render header.html in the main html. The header.html is using bootstrap classes for design primarily bootstrap.css. The page on load successfully loads everything including all the libraries but the view does not have the desired display - i.e. it seems to be devoid of bootstrap. Is there something wrong that I'm doing that my loaded html doesn't display bootstrap and how do I include bootstrap.css in my header.html through require.js in backbone.
Please help.
Related
I'm using #nuxtjs/i18n plugin with nuxt 3 and after I install it I wrote my i18n(config) in the nuxt.config.ts
my code:
i18n: {
locales: [
{
code: 'fa',
iso: 'fa-IR',
name: 'Farsi',
file: 'fa-IR.json',
dir: 'rtl',
},
{
code: 'en',
iso: 'en-US',
name: 'English',
file: 'en-US.json',
dir: 'ltr',
},
],
defaultLocale: 'fa',
detectBrowserLanguage: false,
langDir: "lang",
vueI18n: {
legacy: false,
fallbackLocale: 'fa',
}
}
after that, I use useLocaleHead({}) and useHead({}) in the default.vue(it's in my layout actually)
<script setup lang="ts">
const head = useLocaleHead({
addDirAttribute: true,
addSeoAttributes: true
});
useHead({
htmlAttrs: {
lang: head.value.htmlAttrs!.lang,
dir: head.value.htmlAttrs!.dir
},
});
</script>
but, when I run the project the dir and locale won't dynamic and change if I select another language.
the output images:
as you can see dir and lang attributes on html tag won't change. however, the content's shown as english.
can anyone help how I can develop it with nuxt3??
I have this very weird problem with the React-Quill library component.
I am importing the component as per the NPM instructions, and the editor does load but without any actual CSS applied
The only when the styles are applied are when I link the stylesheet through CDN in the index.html file
<link rel=“stylesheet” href=“//cdn.quilljs.com/1.2.6/quill.snow.css”>
I’ve tested in a stackblitz the same code and it works without such issues.
I am using similar other components such as ‘react-color-palette’ where I do import the styles in the same fashion through the node_modules and there is no problem with it, so it doesn’t make sense to me to be a webpack config problem either but I tested various options with different settings on webpack to no avail.
Even added the CSS to my global CSS which works perfectly fine too, but it still doesn’t apply to the React-Quill
For some reason, the CSS isn't targeting the classes, or its scoped out, but I am unable to understand why that happens
Here is the code
import React, { useState } from 'react';
import hljs from 'highlight.js';
import ReactQuill from 'react-quill';
import 'react-quill/dist/quill.snow.css';
const modules = {
// syntax: {
// highlight: (text: string) => hljs.highlightAuto(text).value,
// },
toolbar: [
[{ header: [1, 2, 3, 4, 5, 6, false] }],
['bold', 'italic', 'underline', 'strike'],
[{ color: [] }],
[{ align: [] }],
[{ indent: '-1' }, { indent: '+1' }],
[{ list: 'ordered' }, { list: 'bullet' }],
['link', 'image', 'video'],
['code-block', 'blockquote'],
[{ script: 'sub' }, { script: 'super' }],
],
clipboard: {
matchVisual: false,
},
syntax: false,
};
const textFormats = [
'font',
'header',
'size',
'bold',
'italic',
'underline',
'strike',
'blockquote',
'background',
'color',
'script',
'list',
'bullet',
'link',
'image',
'video',
'clean',
'code-block',
'indent',
'list',
'align',
];
function RichTextEditor() {
const [value, setValue] = useState('');
hljs.configure({
// useBR: false,
languages: [
'javascript',
'java',
'html',
'xml',
'sql',
'typescript',
'bash',
],
});
return (
<ReactQuill
value={value}
onChange={setValue}
placeholder="Write a new Note"
modules={modules}
formats={textFormats}
/>
);
}
export default RichTextEditor;
Edit
I opened the console and checked in the tags
there are styles currently applied for the react-quill, but seems react modifies the class names:
.RichTextEditor__ql-container__SP9Yv
Where it should really just be
.ql-container
Currently I'm seeing multiple of the same styling within the dev tools. I'm using React and Laravel Mix and not sure why it's showing the same styling multiple times as I'm using React components importing sass files within the different components but it's not recognising the same css when compiling.
Example:
Expected:
It should only be showing the #media once and the single .side-double once.
Laravel Mix file:
const mix = require('laravel-mix');
const path = require('path');
const glob = require('glob');
const PurgeCSSPlugin = require('purgecss-webpack-plugin');
//-- Website Mix --
mix.babelConfig({
plugins: ['#babel/plugin-syntax-dynamic-import', '#babel/plugin-proposal-class-properties', '#babel/plugin-proposal-optional-chaining'],
});
mix.webpackConfig({
watchOptions: {
ignored: /node_modules/
},
stats: {
warnings: false,
},
output: {
chunkFilename: 'website/js/chunks/[chunkhash].js',//replace with your path
},
resolve: {
alias: {
'#fonts': path.resolve(__dirname, 'resources/website/styles/fonts'),
'#images': path.resolve(__dirname, 'resources/website/images')
}
},
plugins: [
new PurgeCSSPlugin({
paths: glob.sync('website/*', { nodir: true }),
})
]
});
mix.options({
postCss: [
require('autoprefixer'),
],
fileLoaderDirs: {
fonts: 'website/fonts',
images: 'website/images'
}
});
mix.js('resources/website/index.js', 'public/website/js').react();
mix.version();
//-- Website Mix End --
Updated
Definition of style:
Where is the style included:
I'm doing a proof of concept to include vuetify in an existing web app that is already partially using vue.
I'm have a concern with CSP, by default all vuetify styles are pushed in inline <style> tags. I don't want to allow style-src 'unsafe-inline' in my CSP.
So far there is 95 inline style tags inserted by vuetify in the <head>section. I did tried the option to put an nonce like described here, but the nonce is only added on the last tag, so still 94 to go. Moreover, I don't have a solid solution to generate nonces, so I'd prefer not relying on this.
Generating a hash for each tag is of course not realist.
I also saw this answer, but I don't think it apply to my context, I'm not server-side renderring.
I am using webpack 4.41.2, vue 2.6.10, vuetify 2.2.8.
Here are some extracts of config files.
webpack.js
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');
[...]
et entryPoints = Object.assign([...], { vendor: ['vue', 'vue-router', 'axios', 'vue-i18n', 'lodash', 'interactjs'] });
var config = {
entry: entryPoints,
output: {
path: __dirname,
filename: 'module/[name].js'
},
[...]
plugins: [
new MiniCssExtractPlugin({ filename: 'module/[name].css', chunkFilename: 'module/[name].css' }),
new VueLoaderPlugin(),
new VuetifyLoaderPlugin()
],
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all'
}
}
},
runtimeChunk: { name: 'manifest' }
}
};
Initialisation file
import Vue from 'vue';
import Vuetify from 'vuetify/lib';
import 'vuetify/dist/vuetify.min.css';
[...]
Vue.use(Vuetify);
const vuetifyOptions = new Vuetify();
// Création de l'instance Vue.js, qui sera dessiner dans l'element définit par l'attribut el
window.Vue = new Vue({
el: '#app',
render: h => h(App),
vuetify: vuetifyOptions
});
I finally found the solution, I was already importing MiniCssExtractPlugin, but used it with less module, but I had to add it to sass module also, used by vuetify.
{
test: /\.s(c|a)ss$/,
use: [
'vue-style-loader',
MiniCssExtractPlugin.loader, // <-- that line
'css-loader',
{
loader: 'sass-loader',
// Requires sass-loader#^8.0.0
options: {
implementation: require('sass'),
sassOptions: {
fiber: require('fibers'),
indentedSyntax: true // optional
}
}
}
]
}
I want to use Bootstrap's alert.js plugin as a front-end asset, but can not figure out how to make it work using brunch-config.js and npm.
At the moment I have such brunch config (it adds jQuery and Bootstrap css to assets):
exports.config = {
files: {
javascripts: {
joinTo: "js/app.js"
},
stylesheets: {
joinTo: "css/app.css"
},
templates: {
joinTo: "js/app.js"
}
},
conventions: {
assets: /^(web\/static\/assets)/
},
paths: {
watched: [
"web/static",
"test/static"
],
public: "priv/static"
},
plugins: {
babel: {
ignore: [/web\/static\/vendor/]
}
},
modules: {
autoRequire: {
"js/app.js": ["web/static/js/app"]
}
},
npm: {
enabled: true,
whitelist: ["phoenix", "phoenix_html", "jquery", "bootstrap"],
globals: {
$: 'jquery',
jQuery: 'jquery'
},
styles: {
bootstrap: ['dist/css/bootstrap.css']
}
}
};
Plugin file is here - ./node_modules/bootstrap/dist/js/umd/alert.js.
One more thing: with this config Brunch actually does something and adds to /js/app.js the needed ./node_modules/bootstrap/dist/js/boostrap.js file which already contains the Alert plugin.
jQuery works properly, Bootstrap css works also. The only problem - Bootstrap js plugins (there are no warnings in console).
In my package.json I have this version of Bootstrap:
{
"repository": {},
"dependencies": {
"babel-brunch": "~6.0.0",
"bootstrap": "^4.0.0-alpha.2",
"brunch": "~2.1.3",
"clean-css-brunch": "~1.8.0",
"css-brunch": "~1.7.0",
"javascript-brunch": "~1.8.0",
"jquery": "^2.2.3",
"phoenix": "file:deps/phoenix",
"phoenix_html": "file:deps/phoenix_html",
"uglify-js-brunch": "~1.7.0"
}
}
Adding require("bootstrap"); to the end of app.js solved the problem for me. I'm far from understanding brunch / bootstrap properly, but AFAIK the javascript side of bootstrap is just a collection of plugins for jQuery. Requiring bootstrap adds the plugins to the global jQuery object (already presented in your brunch-config.js).