question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inline css twice in Vue-CLI 3 with html-webpack-inline-source-plugin

See original GitHub issue

Expected behavior

Size of my css file is 13.8kb, html is 2.8kb. So I wanna that my css file can be inlined with html-webpack-inline-source-plugin.

Current behavior

The size of my html file increased to 30.4kb And I found that my css file was inlined twice.

Config

Adding this plugin by webpack-chain API

// vue.config.js
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin')
module.exports = {
    chainWebpack: config => {
        config.plugin('html').tap(args => {
            args[0].inlineSource = '.css$'
            return args
        }
        config.plugin('inline').use(HtmlWebpackInlineSourcePlugin)
    }
}

When I inspecting my project’s webpack config vue inspect > output.js

// output.js
/* config.plugin('html') */
new HtmlWebpackPlugin(
  {
    templateParameters: function () { /* omitted long function */ },
    template: '/Users/logan/tencent/qgact/src/index.html',
    filename: 'index.html',
    inlineSource: '.css$'
  }
),
/* config.plugin('inline') */
new HtmlWebpackInlineSourcePlugin()

Enviroment

Node.js 10.9.0
@vue/cli-service 3.0.0
webpack 4.15.1
html-webpack-plugin 3.2.0
html-webpack-inline-source-plugin 0.0.10

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

8reactions
logan70commented, Sep 17, 2018

I am experiencing the same issue. Using vue-cli and this plugin, both my JS and CSS are being inlined twice.

Vue-cli 3 would use @vue/preload-webpack-plugin to auto add preload link tag to your html like this

<link href=js/app.js rel=preload as=script>

<link href=css/app.css rel=preload as=style>,

you can modify this plugin’s config in vue.config.js(if you don’t have this file, create it in your project’s root folder)

module.exports = {
  chainWebpack: config => {
    config.plugin('preload')
      .tap(args => {
        args[0].fileBlacklist.push(/\.css/, /app\.js/)
        return args
      })
    config.plugin('inline-source')
      .use(require('html-webpack-inline-source-plugin'))
    config
      .plugin('html')
      .tap(args => {
        args[0].inlineSource = '(\.css|app\.js$)'
        return args
      })
  }
}

If it works, let me know.

0reactions
imaxingcommented, Jan 27, 2022

how you have since resolved this issue? 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inline JavaScript and CSS with webpack - Stack Overflow
I'm using Webpack for bundling resources. Currently it bundle both the CSS and JS files into a separate file called bundle. js. How...
Read more >
Working with CSS | Vue CLI
Working with CSS #. Vue CLI projects come with support for PostCSS, CSS Modules and pre-processors including Sass, Less and Stylus.
Read more >
html-inline-css-webpack-plugin - npm
A webpack plugin for convert external stylesheet to embedded stylesheet, aka document stylesheet. Latest version: 1.11.1, last published: 2 ...
Read more >
Common mistakes to avoid while working with Vue.js
The first thing to do in order to use Vue.js is to import it. If you follow the official guide and use an...
Read more >
Writing multiple Vue components in a single file
Vue CLI 3 +; Vue CLI < 3.0 ... Your Vue.js App"/> </div> </template> <script> import Vue from 'vue'; // inline component with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found