What is the best way to integrate my company's global styles CDN for development purposes into a Vue cli project using Webpack?

After attempting to import through the entry file (main.js)...

import Vue from 'vue'
import App from '@/App'
import router from '@/router/router'
import store from '@/store/store'
import BootstrapVue from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
import { Popover } from 'bootstrap-vue/es/directives'
import 'https://mycompany/main.min.css'

Vue.use(BootstrapVue)
Vue.use(Popover)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  template: '<App/>',
  components: { App }
})

I've explored options within webpack.base.config (externals or publicPath) by referring to various online resources, but none provided a satisfactory solution...

The CSS file obtained via CDN is dependent on and overrides Bootstrap classes, requiring that it be injected after Bootstrap. Can this be achieved with my existing setup in Vue/Webpack, or do I need a task runner like Gulp? Simply injecting the CDN after project build doesn't suffice as style changes should be visible during development work. Is there a simpler method than the aforementioned approaches? And just for clarification, making it an npm package is not an option due to privacy/security concerns.

Answer №1

An effortless approach is to simply add it to your index.html file following all other styles. By the way, did you know that private repositories can be published on npm?

Answer №2

There is a method to handle the template directly used by HtmlWebpackPlugin.

To start, deactivate the inject in build/webpack.prod.conf:

//...
new HtmlWebpackPlugin({
  //...
  inject: false,
  //...
})
//...

In your index.html:

<!DOCTYPE html>
<html>

<head>
  <!-- ... -->
  <% if (process.env.NODE_ENV === 'production') { %>
    <% for (file of htmlWebpackPlugin.files.css) { %>
      <link rel="stylesheet" href="<%= file %>">
    <% } %>
    <link rel="stylesheet" href="https://mycompany/main.min.css">
  <% } %>
</head>

<body>
  <!-- ... -->
  <div id="app"></div>
  <% if (process.env.NODE_ENV !== 'production') { %>
     <link rel="stylesheet" href="https://mycompany/main.min.css">
  <% } else{ %>
    <% for (file of htmlWebpackPlugin.files.js) { %>
      <script src="<%= file %>" type="text/javascript"></script>
    <% } %>
  <% } %>
</body>

</html>

This approach allows manual insertion of static files, giving you control over the order during production. In development, stylesheets are placed in the body tag as it is less critical at that stage.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The navigation bar options are not collapsing as intended

When I resize my page to width:750px;, my navigation bar is not collapsing the items. Despite trying to edit my CSS, I am still clueless. Here is my live page. This is the CSS for my slidebar: @media (max-width: 480px) { /* Slidebar width on extra small ...

Enable sidebar navigation exclusively for mobile and iPad devices

Is there a way to implement a different navigation bar specifically for mobile devices like iPads? I'm considering using this one: Here is the source code: JSFiddle If anyone knows how to achieve this, please share! <link rel="shortcut icon" typ ...

Adding routing links to icons within carousels in Vuetify Nuxt.js: a step-by-step guide

Using js and Vuetify, I am trying to add Routing links to the icons in the Carousels. When I click on an icon, it should open a specific Routing link. However, my attempts have not been successful as the link is not working properly. Below is the code I tr ...

Replacing one <div> with another <div> using a clickable link within the divs

In one of my web pages, there is a div that I'll refer to as div1. Within this div, there is a link called 'Link1'. My goal is to click on Link1, triggering the replacement of div1 with div2. Inside div2 there will be another link, let&apos ...

A dynamic 2-column website design featuring a mobile-friendly layout and an adaptable image

After searching through numerous resources on the topic, I have yet to find a solution to this particular challenge. Is it feasible to create a webpage layout with a text column on the left and an image column on the right that will seamlessly transition i ...

Extract the <br /> tag exclusively from the content inside the div

My experience with WooCommerce has led me to the need to include <br> within a product name. However, this break appears differently as <br /> in the .woocommerce-breadcrumb element. This is what the breadcrumb currently display ...

Webpack 5 lacks compatibility with polyfills for Node.js

I'm facing a challenge with my npm package that is compatible with both Angular and Node.js environments. Recently, I began using the package in Angular v12 projects, but encountered errors like: BREAKING CHANGE: webpack < 5 used to include polyf ...

Creating unique CSS class and ID names dynamically in PHP

I have two divs with randomly generated IDs and I would like to use those IDs in my CSS instead of using inline styles. Is there a way to achieve this without creating a separate PHP file with a CSS header? For example, I want the padding for the ID $id_ ...

Convert a solo row into individual columns within a grid format

My goal is to design a grid layout where each row can be divided into columns independently, similar to the example shown below: https://i.stack.imgur.com/VFPFq.png Here's the code snippet I have been experimenting with: .container { position ...

Flexbox keeps elements on the same line without breaking

I'm currently delving into flexbox and aiming to create a layout similar to the one shown below: https://i.sstatic.net/epnkU.png Here is the code I have come up with: .container { display: flex; gap: 26px; } .flex50 { flex: 50%; ...

Display of content visible via stationary div

Recently, I successfully implemented a fixed div that remains at the top of my webpage. However, I encountered an issue where text would appear through the div when scrolling. You can witness this phenomenon by visiting this site and simply scrolling down ...

Monitoring a folder using webpack

Currently, I have webpack set up in my development environment to bundle all of my dependencies. To help concatenate various js files and include them in a script tag within the markup, I am utilizing the webpack-merge-and-include-globally plugin. Althoug ...

[Vue alert]: There was an issue compiling the template (trying to display a blade command as a string)

I have chosen to utilize laravel6 along with vuejs in order to develop a tutorial website specifically focused on Laravel tutorials. Within my database, I have stored all of the tutorials and some of them include Blade Commands such as @foreach and others. ...

Align the CSS dropdown content to the right rather than the left for a cleaner layout

The information in this dropdown menu is currently aligned to the left of the icon. I would like it to be aligned to the right. Thank you! <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://use.fontawesome.com/releas ...

What is the process for incorporating styles into an external widget?

I am currently navigating my way through NextJS and attempting to incorporate a bespoke stylesheet into my code using a third-party widget. Unfortunately, I have hit a roadblock in this process. The names I have assigned to the style sheet align with what ...

What is the best way to retrieve the input values of dynamically created input fields in Vue 3?

I'm currently working on a Vue 3 form where select fields are generated dynamically using v-for based on the input value of another field. The challenge I'm facing is how to access the values of each select field individually when they all have t ...

Can I apply zebra striping to specific columns in a b-table?

I am working with a basic b-table that has row striping enabled: <b-table :fields="myfields" :items="myData" striped> </b-table> Is it possible to apply striped formatting to only specific columns of the table, rather than ...

Integrate the sum of all items with superior attributes from an array of objects

When using Vue, I am sending a request for cart items and displaying the data as a list of cart items. https://i.sstatic.net/vmmUz.png The data is in JSON format: {"cart": [ { "id": 24, "product_id": "1", "customer_id": "2", "product": { "id ...

Position the image at the center above the text

I am trying to position multiple images side by side, with each image having a date displayed beneath it. The challenge I am facing is that the length of the date extends beyond the width of the image, and I would like to center the image on top of its c ...

When the window width increases, the image within a flexbox causes the flexbox to break

I'm currently working on designing a responsive splash page that covers most of the page (90vh). The layout includes a logo at the top and a simple paragraph at the bottom. I've experimented with using flex-shrink and flex-basis, but it's n ...