Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to inline css files? #234

Open
sowinski opened this issue Jun 4, 2020 · 2 comments
Open

How to inline css files? #234

sowinski opened this issue Jun 4, 2020 · 2 comments

Comments

@sowinski
Copy link

sowinski commented Jun 4, 2020

Hi,

on some pages I would like to inline css files.

Is this possible with django-webpack-loader? If yes how can I do this?

Thank you

@aastashov
Copy link

aastashov commented Jan 4, 2021

Maybe this?

# webpack.config.js
const path = require('path');
const BundleTracker = require('webpack-bundle-tracker');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

  // ...
  entry: {
      main: ['./static/scripts/main.js', './static/styles/main.css'],
      // ...
  }
  output: {
      path: path.resolve('./static/bundles/'),
      filename: '[name].[chunkhash].js',
      hashFunction: 'md5',
      hashDigestLength: 10
  },
  plugins: [
    new BundleTracker({filename: './webpack-static.json'}),
    new MiniCssExtractPlugin({filename: '[name].[contenthash].css'}),
  ],
  module: {
      rules: [
        {
          test: /\.css$/,
          use: [MiniCssExtractPlugin.loader, 'css-loader'],
        }
      ]
    }
  // ...
# file.html
{% load render_bundle from webpack_loader %}

{% block head %}
  {% render_bundle 'main' 'js' %}
  {% render_bundle 'main' 'css' %}
{% endblock %}
# settings.py

WEBPACK_LOADER = {
    'DEFAULT': {
        'BUNDLE_DIR_NAME': 'bundles/',
        'STATS_FILE': BASE_DIR / 'webpack-stats.json',
    },
}

@fjsj
Copy link
Member

fjsj commented Nov 29, 2023

Currently django-webpack-loader doesn't support inlining. The render_bundle template tag only renders links and scripts. Please feel free to open a PR with this desired behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@fjsj @sowinski @joaopslins @aastashov and others