Skip to content

How to extract styles from distribution file? #191

Open
@ledermann

Description

@ledermann

Is it possible to use this component without having the styles in the tag of my applications HTML file?

I'm using Webpack 4, Vue.js 2.5.17, vue-infinite-loading 2.3.5. What I have done in my application.js:

import InfiniteLoading from 'vue-infinite-loading'
Vue.component('infinite-loading', InfiniteLoading)

The component works fine, but in production I want to extract all the CSS (from my application code and from the external components) in one application.css. How can I extract the styles from the compiled JS file?

I've found a workaround by using the source files of the component and use MiniCssExtractPlugin to extract the styles:

In application.js:

import InfiniteLoading from 'vue-infinite-loading/src/index'
Vue.component('infinite-loading', InfiniteLoading)

In environment.js:

const isProduction = process.env.NODE_ENV === 'production'
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
environment.loaders.append('less', {
  test: /\.less$/,
  use: [
    isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
    'css-loader',
    'less-loader'
  ],
})
....

But adding LESS to my project only to extract styles from an external component seems not right to me. Is there a better way?

Maybe this is a more general question regarding Webpack, so I have posted this at Stackoverflow:
https://stackoverflow.com/questions/52929012/webpack-4-how-to-extract-css-from-node-module

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions