Python bindings to webpack

Overview

Unmaintained

This project is unmaintained as it's a complicated solution to a simple problem.

You should try using either https://github.com/owais/django-webpack-loader or https://github.com/markfinger/python-webpack-manifest.

python-webpack

Build Status

Python bindings to webpack, via webpack-build

Documentation

Installation

pip install webpack

and install the JS dependencies with

npm install webpack webpack-build --save

Basic usage

python-webpack provides a high-level interface to a webpack-build server, enabling you to send build requests and receive an object describing the outcome.

To start the server, run

node_modules/.bin/webpack-build -s

Build requests should provide a path to a config file

from webpack.compiler import webpack

bundle = webpack('path/to/webpack.config.js')

The object returned can be passed directly into your template layer, enabling you to inject <script> and <link> elements into your page. The object provides two convenience methods, render_js and render_css which emit elements pointing to the generated assets.

API

webpack

webpack.compiler.webpack allows you to request data from the build server and the manifest reader.

The function requires one argument:

  • config_file - a path to a config file

The following optional arguments are also accepted:

  • context - a dictionary that provides context data that is passed to the config file. In most cases, the CONTEXT setting should be used instead as it allows you to set global defaults.
  • settings - a dictionary of keys which can be used to override settings. In most cases, you'll want to define settings in webpack.conf.settings, but it can be useful to provide overrides without monkey-patching.
  • manifest - an override for the default manifest reader. Should expose a read method.
  • compiler - an override for the default compiler - a webpack-build build server. Should expose a build method.

populate_manifest_file

webpack.manifest.populate_manifest_file generates a manifest file containing the contents of the MANIFEST setting, at the location specified by the MANIFEST_PATH setting.

If you want to override settings during the build process - for example to provide a different STATIC_URL setting - the MANIFEST_SETTINGS setting can be used.

Config files

For webpack's config reference, refer to the official docs.

Config functions

webpack-build uses config files which export a function that returns config objects.

Using config functions provide a number of benefits:

  • functions can generate config objects which reflect the data sent from your python system
  • functions can generate multiple config objects, enabling your config files to act as templates
  • idempotent functions enable webpack-build to safely mutate the object without causing unintended side effects for successive builds

If you are already using config files which export an object, wrap the generation of the object in a function. For example:

// if you currently have
module.exports = {
  // ...
};

// rewrite it as
module.exports = function() {
  return {
    // ...
  };
};

To avoid unintended side-effects and inexplicable behaviour, ensure that your functions are both idempotent and always return an entirely new object. Extending mutable objects is an easy recipe for unhappiness.

Configuring the build

The data sent from python-webpack is available in your config function as the first argument, this enables you to generate a config object which reflects the state of your python system.

A typical use-case is injecting loaders that enable hot module replacement. For example, if you always want to use the babel-loader, but you only want react-hot-loader when hot module replacement is available:

module.exports = function(opts) {
  return {
    // ...
    module: {
      loaders: [
        {
          test: /\.jsx?$/,
      	  exclude: /(node_modules|bower_components)/,
      	  loader: (opts.hmr ? 'react-hot-loader!' : '') + 'babel-loader'
        }
      ]
    }
  };
};

The opts object provided to your functions is sent from python-webpack and follows webpack-build's build options.

Passing data to the config layer

You can send extra data to your config function by specifying the CONTEXT setting.

For example, if your CONTEXT setting looked like {'COMPRESS': True}, your function could use the COMPRESS flag to activate compression:

var webpack = require('webpack');

module.exports = function(opts) {
  var config = {
    // ...
  };
  
  if (opts.context.COMPRESS) {
    config.plugins.push(
      new webpack.optimize.UglifyJsPlugin()
    );
  }
  
  return config;
};

The CONTEXT setting defines global defaults, but you can also specify per-build values by providing the context argument to the webpack function.

Using context allows you to treat config functions as factories or templates, which can assist with reducing boilerplate and reusing config files across multiple contexts.

Using relative paths to config files

If you want to use relative paths to config files, you should specify the CONFIG_DIRS setting. When a relative path is provided, python-webpack looks sequentially through the directories until it finds a match.

Output paths

Be aware that the output.path property on config objects is overridden automatically, you can leave the setting undefined and webpack-build will redirect all output to your OUTPUT_ROOT.

To avoid file name collisions, builds are uniquely identified by hashing the options object sent to webpack-build. By default, your assets are placed in a directory equivalent to

os.path.join(OUTPUT_ROOT, 'webpack_assets', options_hash)

Build server

python-webpack relies on webpack-build to expose a high-level API around webpack such that it can be easily integrated into an external system. webpack-build's server is used to provide network access to the library's functionality.

A build server can be started with

node_modules/.bin/webpack-build -s

Hot module replacement

If you set the HMR setting to True, assets that are rendered on the client-side will open sockets to the build server and listen for change notifications. When the assets have been rebuilt, they will attempt to automatically update themselves within the browser. If they are unable to, they will log to the console indicating that you will need to refresh for the changes to be applied.

When HMR is True, webpack-build will automatically mutate config objects by:

  • adding a HMR client to the generated bundle
  • adding a HotModuleReplacementPlugin
  • defining output.publicPath
  • defining recordsPath

If you want to change your config for situations where the python layer has requested HMR, use the hmr flag on the options argument provided to config functions.

Overriding the build server

If you want to replace the build server with your own compiler, you can use the compiler argument on the webpack function. Composing a wrapper around webpack is one solution, for example:

from webpack.compiler import webpack

class MyCompiler:
    def build(config_file, *args, **kwargs):
        # ...
    
my_compiler = MyCompiler()
        
def my_webpack_function(*args, **kwargs):
    kwargs['compiler'] = my_compiler
    return webpack(*args, **kwargs)

Offline manifests

Offline manifests are JSON files which allow python-webpack to cache the output from webpack-build. Manifests are useful as an optimisation for production environments where you do not want a build server running.

Generating manifests

The easiest way to generate manifests is to define the MANIFEST and MANIFEST_PATH settings.

The MANIFEST setting should an iterable containing config files. For example:

(
    'path/to/some/webpack.config.js',
    'path/to/another/webpack.config.js',
)

The MANIFEST_PATH setting should be an absolute path to a file that the manifest will be written to and read from. For example:

os.path.join(os.getcwd(), 'webpack.manifest.json')

To generate a manifest, call the populate_manifest_file function. For example:

from webpack.manifest import populate_manifest_file

populate_manifest_file()

Once your manifest has been generated, the USE_MANIFEST setting is used to indicate that all data should be served from the manifest file. When USE_MANIFEST is True, any requests which are not contained within the manifest will cause errors to be raised.

Using context in a manifest

If you want to generate a manifest which contains specific context for each config file, set MANIFEST to a dictionary where the keys are config files and the values are iterables containing context objects. For example:

{
    # Build this file with a context
    'path/to/some/webpack.config.js': (
        {'foo': True},
    ),
    # Build this file without context
    'path/to/another/webpack.config.js': (),
    # Build this file twice, with two different contexts
    'path/to/yet/another/webpack.config.js': (
        {'foo': True},
        {'bar': True},
    ),
}

Note: if you call webpack with the USE_MANIFEST setting activated, you must specify the exact same context as defined in the MANIFEST setting.

Manifest keys

Manifest keys are the paths to the config files. If you want to deploy your manifests to another environment, you will likely need to use relative paths in coordination with the CONFIG_DIRS setting.

If have specified context for a config file, the keys are generated by appending a hash of the context to the path. Hence, you must specify the exact same context when calling webpack.

Overriding the manifest reader

The manifest handler that ships with webpack depends heavily on path resolution and context hashes to map requests to entries in the manifest. While this behaviour ensures an explicit and deterministic outcome, it can make it difficult to ensure portablity when deploying manifests to other locations or servers.

If you want to use your own manifest reader, one solution is to compose a wrapper function around webpack and override the manifest argument. For example:

from webpack.compiler import webpack

class MyManifest():
    def read(config_file, context):
        """This method is called by the compiler and should return an object"""
        # ...
        
my_manifest = MyManifest()
        
def my_webpack_function(*args, **kwargs):
    kwargs['manifest'] = my_manifest
    return webpack(*args, **kwargs)

Settings

Settings can be defined by calling webpack.conf.settings.configure with keyword arguments matching the setting that you want to define. For example:

from webpack.conf import settings

DEBUG = True

settings.configure(
    OUTPUT_ROOT='/path/to/your/output_root',
    STATIC_URL='/static/',
    WATCH=DEBUG,
    HMR=DEBUG,
)

Note: in a Django project, you should declare the settings as keys in a dictionary named WEBPACK within your settings file. python-webpack introspects Django's settings during startup and will configure itself from the WEBPACK dictionary.

OUTPUT_ROOT

An absolute path to the root directory that you use for static assets. For example, '/path/to/your/output_root'.

This setting must be defined.

Default: None

STATIC_URL

The root url that your static assets are served from. For example, '/static/'.

This setting must be defined.

Default: None

BUILD_URL

The url that build requests are sent to, this url should expose webpack-build.

Default: 'http://127.0.0.1:9009/build'

CONFIG_DIRS

A list of directories that will be used to resolve relative paths to config files.

Default: None

WATCH

A boolean flag which indicates that file watchers should be set to watch the assets's source files. When a change is detected, the files which have changed are recompiled in the background so that the assets are ready for the next request. Set this to True in development environments.

Default: False

HMR

A boolean flag indicating that webpack-build should inject a hmr runtime into the generated assets. Set this to True in development environments.

Default: False

CONTEXT

The default context provided to config functions - you can use this to pass data and flags down to your config functions. If defined, the setting should be a dictionary.

Default: None

CONFIG_DIRS

An iterable of directories that will be used to resolve relative paths to config files.

Default: None

MANIFEST

An object containing config files which are used to populate an offline manifest. Can be either an iterable of paths or a dictionary mapping paths to context objects.

Default: None

USE_MANIFEST

A flag indicating that python-webpack should use the manifest file, rather than opening connections to a build server.

Default: False

MANIFEST_PATH

An absolute path to the file used to store the manifest.

Default: None

MANIFEST_SETTINGS

A dictionary of values that are used during manifest generation to override python-webpack's settings.

Default:

{
	# Force the compiler to connect to the build server
	'USE_MANIFEST': False,
	# Ensure that the server does not add a hmr runtime
	'HMR': False,
}

CACHE

A flag indicating that webpack-build should maintain a persistent file cache. The file cache is used to improve response times for builds that have already been completed.

Default: True

CACHE_DIR

An override for the directory that webpack-build uses to store cache files.

Default: None

OUTPUT_DIR

The directory in OUTPUT_ROOT which webpack will output all assets to.

Default: 'webpack_assets'

AGGREGATE_TIMEOUT

The delay between the detection of a change in your source files and the start of a compiler's rebuild process.

Default: 200

POLL

If defined, this is a flag which indicates that watching compilers should poll for file changes, rather than relying on the OS for notifications.

If the compiler is not detecting changes to your files, setting this to True may resolve the problem.

Default: None

Django integration

Installation and configuration

The following configuration should be placed in your settings files to enable python-webpack to function with Django.

Add 'webpack' to your INSTALLED_APPS

INSTALLED_APPS = (
    # ...
    'webpack',
)

Add 'webpack.django_integration.WebpackFinder' to your STATICFILES_FINDERS

STATICFILES_FINDERS = (
    # ...
    'webpack.django_integration.WebpackFinder',
)

Configure webpack to respect your project's configuration

WEBPACK = {
    'OUTPUT_ROOT': '/path/to/your/output_root',
    'STATIC_URL': STATIC_URL,
    'WATCH': DEBUG,
    'HMR': DEBUG,
}

Template tags

A template tag is provided to integrate webpack at the template layer.

{% load webpack %}

{% webpack 'path/to/webpack.config.js' as bundle %}

{{ bundle.render_css|safe }}

{{ bundle.render_js|safe }}

Running the tests

pip install -r requirements.txt
npm install
python runtests.py
Comments
  • python-webpack stops rendering often

    python-webpack stops rendering often

    I think I've found a bug in python-webpack or python-js-host.

    Bundle's render method stops working if I save a file more than once in quick succession or and sometimes if an error occurs. It stops rendering the script tags in template.

    Things work again if I restart jshost or make a change to one of the source files and refresh the page.

    I guess this happens when webpack is still building and django sends a request for the bundle. Instead of blocking, the bundle returns an empty string instead of blocking the call.

    Also, I'm running jshost manually like this, ./node_modules/.bin/js-host host.config.js

    I've also tried to increase WATCH_DELAY setting to 1000 from 200 but the issue remains. Everything else is set to the default value mentioned in the docs.

    My webpack config looks like this (but I doubt it has got anything to do with that).

    var webpack = require('webpack');
    var BowerWebpackPlugin = require("bower-webpack-plugin");
    
    module.exports = {
        context: __dirname,
        entry: "./main.js",
        output: {
            path: "[bundle_dir]",
            filename: "[name]-[hash].js"
        },
    
        plugins: [
          new BowerWebpackPlugin(),
          new webpack.ProvidePlugin({
            $:      "jquery",
            jQuery: "jquery",
            hammerjs: "hammerjs",
            react: "React"
          })
        ],
    
        module: {
          loaders: [
              { test: /\.jsx$/, loader: 'jsx-loader?insertPragma=React.DOM&harmony' },
              { test: /\.css$/, loader: "style-loader!css-loader" },
              { test: /\.scss$/, loader: "style!css!sass!" },
              { test: /\.less$/, loader: "style-loader!css-loader!less-loader" },
              { test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,   loader: "url?limit=10000&minetype=application/font-woff" },
              { test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,  loader: "url?limit=10000&minetype=application/font-woff" },
              { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,    loader: "url?limit=10000&minetype=application/octet-stream" },
              { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,    loader: "file" },
              { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,    loader: "url?limit=10000&minetype=image/svg+xml" }
          ],
        },
    
        resolve: {
          modulesDirectories: ['web_modules', 'node_modules', 'bower_components'],
          extensions: ['', '.js', '.jsx']
        },
    }
    
    opened by owais 12
  • Add templatetag and staticfiles storage for Django

    Add templatetag and staticfiles storage for Django

    Hi,

    I made a templatetag and a storage backend that allows you to pre-compile the webpack bundles. I modeled the interface sort of close to django-compressor's offline mode and the code for the WebpackOfflineStorageMixin is based on the ManifestFileStorage from django.

    I also adding some docs for how to use it, but I wasn't sure where you would have put the docs, so I just made a new section for it.

    Before you merge this, I think we need to write some tests for the WebpackOfflineStorageMixin, but in order to do that, we need a way of overriding the settings, which is a little hard with the optional_django stuff. Do you have any idea for what we could do with that?

    Thanks!

    opened by rockymeza 9
  • More Windows issues after getting js-host working...

    More Windows issues after getting js-host working...

    I've looked at this one for a bit now as well and am currently stumped, here's the traceback...

    Request Method: GET
    Request URL:    http://127.0.0.1:8000/test
    Django Version: 1.8.1
    Exception Type: BundlingError
    Exception Value:    
    webpack: EntryModuleNotFoundError: Entry module not found: Error: Cannot resolve 'file' or 'directory' ./app.js in C:devprojectstaticsrcadminscripts
        at Tapable.<anonymous> (C:\dev\project\static\node_modules\webpack\lib\Compilation.js:346:28)
        at Tapable.<anonymous> (C:\dev\project\static\node_modules\webpack\lib\NormalModuleFactory.js:55:19)
        at C:\dev\project\static\node_modules\webpack\node_modules\async\lib\async.js:254:17
        at done (C:\dev\project\static\node_modules\webpack\node_modules\async\lib\async.js:129:15)
        at C:\dev\project\static\node_modules\webpack\node_modules\async\lib\async.js:32:16
        at C:\dev\project\static\node_modules\webpack\node_modules\async\lib\async.js:251:21
        at C:\dev\project\static\node_modules\webpack\node_modules\async\lib\async.js:575:34
        at C:\dev\project\static\node_modules\webpack\node_modules\enhanced-resolve\lib\UnsafeCachePlugin.js:24:19
        at onResolved (C:\dev\project\static\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:38:18)
        at C:\dev\project\static\node_modules\webpack\node_modules\enhanced-resolve\lib\Resolver.js:127:10
    Exception Location: C:\Python34\lib\site-packages\js_host\function.py in send_request, line 92
    Python Executable:  C:\Python34\python.exe
    Python Version: 3.4.2
    

    I guess it has something to do with the windows path backslashes...?

    opened by anyong 9
  • Settings issue in Django 1.6

    Settings issue in Django 1.6

    Hello there,

    I'm using python-webpack in a django app, and settings don't seem to be passed.

    In my settings :

    DJANGO_ROOT = dirname(dirname(abspath(__file__)))
    # [...]
    STATIC_ROOT = normpath(join(DJANGO_ROOT, '../media/static'))
    STATIC_URL = '/media/static/'
    # [...]
    DEBUG = True
    # [...]
    ########## WEBPACK
    WEBPACK = {
        'STATIC_ROOT': STATIC_ROOT,
        'STATIC_URL': STATIC_URL,
        'WATCH': DEBUG,
        'HMR': DEBUG,
    }
    

    In my view :

    from webpack.compiler import webpack
    # [...]
    def some_view(request, arg):
        # [...]
        bundle=webpack('webpack.js')
    

    And I'm getting :

    Traceback (most recent call last):
      File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
        self.result = application(self.environ, self.start_response)
      File "/home/vagrant/.venv/backend/local/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
        return self.application(environ, start_response)
      File "/home/vagrant/.venv/backend/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 206, in __call__
        response = self.get_response(request)
      File "/home/vagrant/.venv/backend/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 194, in get_response
        response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
      File "/home/vagrant/.venv/backend/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 112, in get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "/backend/frontend/views.py", line 77, in some_view
        bundle=webpack('webpack.js')
      File "/home/vagrant/.venv/backend/local/lib/python2.7/site-packages/webpack/compiler.py", line 22, in webpack
        setting_overrides=settings,
      File "/home/vagrant/.venv/backend/local/lib/python2.7/site-packages/webpack/build_server.py", line 25, in build
        setting_overrides=setting_overrides,
      File "/home/vagrant/.venv/backend/local/lib/python2.7/site-packages/webpack/options.py", line 17, in generate_compiler_options
        raise ImproperlyConfigured('webpack.conf.settings.STATIC_ROOT has not been defined.')
    ImproperlyConfigured: webpack.conf.settings.STATIC_ROOT has not been defined.
    
    opened by njoqi 6
  • Needs compatibility with webpack-build 1.0.0

    Needs compatibility with webpack-build 1.0.0

    Noticed some changes in webpack-build 1.0.0 that requires changes in python-webpack as well (or at least in the documentation). From a quick test, running node_modules/.bin/webpack-build doesn't actually run the server anymore and outputs static files in the wrong location.

    opened by jbinney 4
  • Clean up docs

    Clean up docs

    Hi,

    I came across this trying to research good client-side build/deploy practices.

    Your example code:

    from django_webpack.compiler import webpack
    bundle = webpack('path/to/webpack.config.js')
    # Returns a string containing <script> elements pointing to the bundle
    bundle.render()
    

    My first thought was that this was meant to be used in management command that's run on a production server for every deploy. An extra step to run after 'collectstatic'...

    But the fact that it returns a string makes it look like it's more like to be view code - or probably part of a templatetag.

    Am I misunderstanding things?

    opened by andybak 4
  • Config file writer

    Config file writer

    Need a way to deterministically write config files such that the path is constant so long as the content does not change.

    from django_webpack.config_file import write_config_file
    
    path = write_config_file(contents, prefix='some_identifier')
    
    # `path` = '<BUNDLE_ROOT>/config_files/some_identifier_<hash_of_contents>.webpack.config.js'
    

    markfinger/django-react#32

    opened by markfinger 3
  • Use in production

    Use in production

    The dev branch differs a lot from the master, I'd like to know how you are currently using it in production. You mention in #32 that you are also using django-compressor. I'd like to know how you are integrating the two. Thanks.

    opened by TheoRyley 2
  • Cache manifest handling

    Cache manifest handling

    #20 laid a lot of the groundwork and proved the worth (it's annoying having to warm up and maintain a build server)

    Workflow

    • user runs webpack command
    • system builds the config files which have been listed
    • writes the output to a manifest file
    opened by markfinger 2
  • Added templatetag

    Added templatetag

    Much simpler way to insert bundle into HTML.

    {% load webpack %}
    
    <head>
      {% webpack_bundle "my_app/webpack.config.js" %}
    </head>
    
    opened by maxpoletaev 2
  • Optimise component watching

    Optimise component watching

    On first render require the component, and start bundling it in the background. The second request should hit the bundled component. Maybe put this behaviour behind a flag defaulting to True.

    opened by markfinger 2
  • Bump flask from 0.10.1 to 1.0 in /examples/flask

    Bump flask from 0.10.1 to 1.0 in /examples/flask

    Bumps flask from 0.10.1 to 1.0.

    Release notes

    Sourced from flask's releases.

    1.0

    The Pallets team is pleased to release Flask 1.0. [Read the announcement on our blog.](https://www.palletsprojects.com/blog/flask-1-0-released/

    There are over a year's worth of changes in this release. Many features have been improved or changed. Read the changelog to understand how your project's code will be affected.

    JSON Security Fix

    Flask previously decoded incoming JSON bytes using the content type of the request. Although JSON should only be encoded as UTF-8, Flask was more lenient. However, Python includes non-text related encodings that could result in unexpected memory use by a request.

    Flask will now detect the encoding of incoming JSON data as one of the supported UTF encodings, and will not allow arbitrary encodings from the request.

    Install or Upgrade

    Install from PyPI with pip:

    pip install -U Flask
    

    0.12.4

    This is a repackage of 0.12.3 to fix an issue with how the package was built.

    Upgrade

    Upgrade from PyPI with pip. Use a version identifier if you want to stay at 0.12:

    pip install -U 'Flask~=0.12.4'
    

    0.12.3

    This release includes an important security fix for JSON and a minor backport for CLI support in PyCharm. It is provided for projects that cannot update to Flask 1.0 immediately. See the 1.0 announcement and update to it instead if possible.

    JSON Security Fix

    Flask previously decoded incoming JSON bytes using the content type of the request. Although JSON should only be encoded as UTF-8, Flask was more lenient. However, Python includes non-text related encodings that could result in unexpected memory use by a request.

    Flask will now detect the encoding of incoming JSON data as one of the supported UTF encodings, and will not allow arbitrary encodings from the request.

    Upgrade

    Upgrade from PyPI with pip. Use a version identifier if you want to stay at 0.12:

    pip install -U 'Flask~=0.12.3'
    
    ... (truncated)
    Changelog

    Sourced from flask's changelog.

    Version 1.0

    Released 2018-04-26

    • Python 2.6 and 3.3 are no longer supported.
    • Bump minimum dependency versions to the latest stable versions: Werkzeug >= 0.14, Jinja >= 2.10, itsdangerous >= 0.24, Click >= 5.1. :issue:2586
    • Skip :meth:app.run <Flask.run> when a Flask application is run from the command line. This avoids some behavior that was confusing to debug.
    • Change the default for :data:JSONIFY_PRETTYPRINT_REGULAR to False. :func:~json.jsonify returns a compact format by default, and an indented format in debug mode. :pr:2193
    • :meth:Flask.__init__ <Flask> accepts the host_matching argument and sets it on :attr:~Flask.url_map. :issue:1559
    • :meth:Flask.__init__ <Flask> accepts the static_host argument and passes it as the host argument when defining the static route. :issue:1559
    • :func:send_file supports Unicode in attachment_filename. :pr:2223
    • Pass _scheme argument from :func:url_for to :meth:~Flask.handle_url_build_error. :pr:2017
    • :meth:~Flask.add_url_rule accepts the provide_automatic_options argument to disable adding the OPTIONS method. :pr:1489
    • :class:~views.MethodView subclasses inherit method handlers from base classes. :pr:1936
    • Errors caused while opening the session at the beginning of the request are handled by the app's error handlers. :pr:2254
    • Blueprints gained :attr:~Blueprint.json_encoder and :attr:~Blueprint.json_decoder attributes to override the app's encoder and decoder. :pr:1898
    • :meth:Flask.make_response raises TypeError instead of ValueError for bad response types. The error messages have been improved to describe why the type is invalid. :pr:2256
    • Add routes CLI command to output routes registered on the application. :pr:2259
    • Show warning when session cookie domain is a bare hostname or an IP address, as these may not behave properly in some browsers, such as Chrome. :pr:2282
    • Allow IP address as exact session cookie domain. :pr:2282
    • SESSION_COOKIE_DOMAIN is set if it is detected through SERVER_NAME. :pr:2282
    • Auto-detect zero-argument app factory called create_app or make_app from FLASK_APP. :pr:2297
    • Factory functions are not required to take a script_info parameter to work with the flask command. If they take a single parameter or a parameter named script_info, the
    ... (truncated)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Support collectstatic

    Support collectstatic

    Right now, python-webpack supports findstatic, which is used by Django to locate and serve static files during development. However, it doesn't support collectstatic, which is used by Django to gather all static files and move them into STATIC_ROOT for deployment. It seems that python-webpack bypasses collectstatic by outputting webpack_assets directly into the STATIC_ROOT directory, with the assumption that you will simply sync the STATIC_ROOT directory with your static server (e.g. S3). Unfortunately, many people use django-storages (example), which relies on the collectstatic step to sync static files with S3.

    Fortunately, the only necessary change to support collectstatic is removing the list() override in WebpackFinder - the implementation in BaseStorageFinder works just fine. If we want collectstatic to work properly though, we shouldn't encourage people to output webpack_assets directly to STATIC_ROOT anymore, as this can cause issues like this. I'm proposing changing the name of this setting to OUTPUT_ROOT and recommending people set it to something like BASE_DIR+'generated_assets'. Of course, if people aren't interested in using collectstatic, they can still set OUTPUT_ROOT=STATIC_ROOT and get the same behavior.

    opened by jbinney 0
  • Chunking aka code splitting

    Chunking aka code splitting

    One cool thing about webpack is that it allows you to output multiple bundles for production. It's not clear to me if this is even possible in the python-webpack world. If it is, some documentation would be nice, if not, it would be a great feature.

    opened by ntucker 4
Owner
Mark Finger
Mark Finger
A django compressor tool that bundles css, js files to a single css, js file with webpack and updates your html files with respective css, js file path.

django-webpacker's documentation: Introduction: django-webpacker is a django compressor tool which bundles css, js files to a single css, js file with

MicroPyramid 72 Aug 18, 2022
HTML minifier for Python frameworks (not only Django, despite the name).

django-htmlmin django-html is an HTML minifier for Python, with full support for HTML 5. It supports Django, Flask and many other Python web framework

Cobra Team 536 Dec 25, 2022
Python bindings to webpack

Unmaintained This project is unmaintained as it's a complicated solution to a simple problem. You should try using either https://github.com/owais/dja

Mark Finger 62 Apr 15, 2022
A flask template with Bootstrap 4, asset bundling+minification with webpack, starter templates, and registration/authentication. For use with cookiecutter.

cookiecutter-flask A Flask template for cookiecutter. (Supports Python ≥ 3.6) See this repo for an example project generated from the most recent vers

null 4.3k Dec 29, 2022
Transparently use webpack with django

Looking for maintainers This repository is unmaintained as I don't have any free time to dedicate to this effort. If you or your organisation are heav

Owais Lone 2.4k Jan 6, 2023
Transparently use webpack with django

Looking for maintainers This repository is unmaintained as I don't have any free time to dedicate to this effort. If you or your organisation are heav

null 2.4k Dec 24, 2022
Transparently use webpack with django

django-webpack-loader Read http://owaislone.org/blog/webpack-plus-reactjs-and-django/ for a detailed step by step guide on setting up webpack with dja

null 2.4k Jan 6, 2023
A django compressor tool that bundles css, js files to a single css, js file with webpack and updates your html files with respective css, js file path.

django-webpacker's documentation: Introduction: django-webpacker is a django compressor tool which bundles css, js files to a single css, js file with

MicroPyramid 72 Aug 18, 2022
Use webpack to generate your static bundles without django's staticfiles or opaque wrappers.

django-webpack-loader Use webpack to generate your static bundles without django's staticfiles or opaque wrappers. Django webpack loader consumes the

null 2.4k Dec 24, 2022
Python bindings and utilities for GeoJSON

geojson This Python library contains: Functions for encoding and decoding GeoJSON formatted data Classes for all GeoJSON Objects An implementation of

Jazzband 765 Jan 6, 2023
Python bindings to the dutch NLP tool Frog (pos tagger, lemmatiser, NER tagger, morphological analysis, shallow parser, dependency parser)

Frog for Python This is a Python binding to the Natural Language Processing suite Frog. Frog is intended for Dutch and performs part-of-speech tagging

Maarten van Gompel 46 Dec 14, 2022
Python bindings for the simdjson project.

pysimdjson Python bindings for the simdjson project, a SIMD-accelerated JSON parser. If SIMD instructions are unavailable a fallback parser is used, m

Tyler Kennedy 562 Jan 1, 2023
Ultra fast JSON decoder and encoder written in C with Python bindings

UltraJSON UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 3.6+. Install with pip: $ python -m pip insta

null 3.9k Dec 31, 2022
Python bindings for Alexa Web Information Service (AWIS) API

Attention! This package is no longer maintained. See this ticket for more info. Wraps Alexa Web Information Service. Usage Making UrlInfo requests: ap

Atamert Ölçgen 51 Feb 12, 2022
Python bindings for ArrayFire: A general purpose GPU library.

ArrayFire Python Bindings ArrayFire is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific

ArrayFire 402 Dec 20, 2022
Python bindings for BigML.io

BigML Python Bindings BigML makes machine learning easy by taking care of the details required to add data-driven decisions and predictive power to yo

BigML Inc, Machine Learning made easy 271 Dec 27, 2022
Disqus API bindings for Python

disqus-python Let's start with installing the API: pip install disqus-python Use the API by instantiating it, and then calling the method through dott

DISQUS 163 Oct 14, 2022
Python bindings to the Syncthing REST interface.

python-syncthing Python bindings to the Syncthing REST interface. Python API Documentation Syncthing Syncthing REST Documentation Syncthing Forums $ p

Blake VandeMerwe 64 Aug 13, 2022
Ultra fast JSON decoder and encoder written in C with Python bindings

UltraJSON UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 3.6+. Install with pip: $ python -m pip insta

null 3.9k Jan 2, 2023
Python bindings for the simdjson project.

pysimdjson Python bindings for the simdjson project, a SIMD-accelerated JSON parser. If SIMD instructions are unavailable a fallback parser is used, m

Tyler Kennedy 562 Jan 8, 2023