Search code examples
djangodockerwebpackminifybundling-and-minification

Webpack for Django Project on Docker (Production)


I have a Django project, and I've successfully installed and run Webback with the purpose of minifying frontend files (CSS, JS, HTML) using npm (and creating config.js) - I want to make Docker do this job automatically from the production server side.

I tried to do it from the backend through Django settings (STATIC_FILE), but failed.

var config = {
    module: {},
};

var src = '/xx/xx/xx/xx/xx/xx/';

var File1JS = Object.assign({}, config, {
  entry: src + 'static/assets/js/file1.js', /// Source File
  output:{
    filename:'file1.js',
    path: src + 'static/assets/js' /// Ourput File (Minified File)
  }
});
var File2JS = Object.assign({}, config,{
  entry: src + 'static/assets/js/file2.js',
  output:{
    filename:'file2.js',
    path: src + 'static/assets/js'
  }
});

module.exports = {
  File1JS, File2JS
};

Any advice or help?


Solution

  • Running webpack at your production server sounds like not the best idea. The most straightforward approach is to build your frontend code during continuous integration (CI) & just put the output files where ever you need them.

    Having webpack on your production server would be a necessity if your application accepts js uploads from users & then run it on the server. This setup would have so many security concerns - for attacks to your server, to abusing your resources.