Skip to content

Commit

Permalink
Merge 427a5b0 into 23b2067
Browse files Browse the repository at this point in the history
  • Loading branch information
ntarocco committed Jun 29, 2018
2 parents 23b2067 + 427a5b0 commit 5fb51ec
Show file tree
Hide file tree
Showing 9 changed files with 381 additions and 122 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ python:
before_install:
- "nvm install 6; nvm use 6"
- "npm install -g webpack"
- "npm install -g webpack-cli"
- "travis_retry pip install --upgrade pip setuptools py"
- "travis_retry pip install twine wheel coveralls requirements-builder"
- "requirements-builder -e all --level=min setup.py > .travis-lowest-requirements.txt"
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Optionally you can use PyWebpack to also:

* **Inject configuration:** PyWebpack will write a ``config.json`` into
your webpack project, which you can import in your webpack configuration. You
define what goes in the config, but you can use to let e.g. Webpack know
about output paths or dynamic entry points.
can define what goes in the config e.g. Let webpack knows about output paths or
dynamic entry points.
* **Collect bundles:** If you Webpack project is spread over multiple Python
packages, PyWebpack can help you dynamically assemble the files into a
Webpack project. This is useful if you don't know until runtime which
Webpack project. This is useful if you don't know until build time which
packages are installed.
95 changes: 1 addition & 94 deletions docs/usage.rst
Original file line number Diff line number Diff line change
@@ -1,97 +1,4 @@
Usage
=====

A simple example
----------------

Let's take a simple ``package.json``::

{
"private": true,
"name": "example",
"version": "0.0.1",
"author": "myself",
"license": "WTFPL",
"description": "example",
"dependencies": {
"jquery": "^3.2.1"
}
}

Let's add to it a run script that executes webpack::

"scripts": {
"build": "webpack --config webpack.config.js"
}

And the corresponding ``webpack.config.js``::

var path = require('path');

module.exports = {
context: path.resolve(__dirname, 'src'),
entry: './index.js',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
}
};

We can easily wrap our project in a :class:`~pywebpack.project.WebpackProject` object::

from pywebpack.project import WebpackProject
project = WebpackProject('.')

This will allow us to install the dependencies::

project.install()

And invoke webpack to build the assets::

project.build()

Alternative, :meth:`~pywebpack.project.WebpackProject.buildall` can be used to execute both tasks at once.


Using a manifest
----------------

Manifests help you deal with long-term caching, by providing a mapping between the name of a resource and its "hashed"
version::

{
"main.js": "main.75244bb780acd727ebd3.js"
}

This package supports manifest files that are compatible with `webpack-manifest-plugin`_, `webpack-yam-plugin`_ and
`webpack-bundle-tracker`_.

You will normally want webpack to add a hash of a file's contents to its name::

output: {
filename: '[name].[chunkhash].js',
path: path.resolve(__dirname, 'dist')
}

And then have it invoke your favorite manifest plugin::

plugins: [
new ManifestPlugin({
fileName: 'manifest.json'
})
]

:class:`~pywebpack.manifests.ManifestLoader` should be able to load a manifest in any of those formats::

manifest = ManifestLoader.load('/path/to/dist/manifest.json')

The manifest entries can be retrieved as object attributes or items::

manifest.myresource
manifest['myresource']
manifest['main.js']


.. _webpack-manifest-plugin: https://www.npmjs.com/package/webpack-manifest-plugin
.. _webpack-yam-plugin: https://www.npmjs.com/package/webpack-yam-plugin
.. _webpack-bundle-tracker: https://www.npmjs.com/package/webpack-bundle-tracker
.. automodule:: pywebpack
Loading

0 comments on commit 5fb51ec

Please sign in to comment.