Skip to content

Commit 7bea208

Browse files
mikeenglandowais
authored andcommitted
Added support for .js.gz and .css.gz files
1 parent 9e51758 commit 7bea208

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

requirements-dev.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
twine==1.7.4
2+
Django==1.10.1
3+
django-jinja==2.2.1
4+
django-jinja2==0.1
5+
unittest2==1.1.0

tests/app/tests/test_webpack.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ def test_simple_and_css_extract(self):
6767
self.assertEqual(main[0]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/main.js'))
6868
self.assertEqual(main[1]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/styles.css'))
6969

70+
def test_js_gzip_extract(self):
71+
self.compile_bundles('webpack.config.gzipTest.js')
72+
assets = get_loader(DEFAULT_CONFIG).get_assets()
73+
self.assertEqual(assets['status'], 'done')
74+
self.assertIn('chunks', assets)
75+
76+
chunks = assets['chunks']
77+
self.assertIn('main', chunks)
78+
self.assertEqual(len(chunks), 1)
79+
80+
main = chunks['main']
81+
self.assertEqual(main[0]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/main.js.gz'))
82+
self.assertEqual(main[1]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/styles.css'))
83+
7084
def test_static_url(self):
7185
self.compile_bundles('webpack.config.publicPath.js')
7286
assets = get_loader(DEFAULT_CONFIG).get_assets()

tests/webpack.config.gzipTest.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var path = require("path");
2+
var webpack = require('webpack');
3+
var BundleTracker = require('webpack-bundle-tracker');
4+
var ExtractTextPlugin = require("extract-text-webpack-plugin");
5+
6+
7+
module.exports = {
8+
context: __dirname,
9+
entry: './assets/js/index',
10+
output: {
11+
path: path.resolve('./assets/bundles/'),
12+
filename: "[name].js.gz"
13+
},
14+
15+
plugins: [
16+
new ExtractTextPlugin("styles.css"),
17+
new BundleTracker({filename: './webpack-stats.json'}),
18+
],
19+
20+
module: {
21+
loaders: [
22+
// we pass the output from babel loader to react-hot loader
23+
{ test: /\.jsx?$/, exclude: /node_modules/, loaders: ['babel'], },
24+
{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }
25+
],
26+
},
27+
28+
resolve: {
29+
modulesDirectories: ['node_modules', 'bower_components'],
30+
extensions: ['', '.js', '.jsx']
31+
},
32+
}

webpack_loader/templatetags/webpack_loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ def filter_by_extension(bundle, extension):
1717
def render_as_tags(bundle, attrs):
1818
tags = []
1919
for chunk in bundle:
20-
if chunk['name'].endswith('.js'):
20+
if chunk['name'].endswith(('.js', '.js.gz')):
2121
tags.append((
2222
'<script type="text/javascript" src="{0}" {1}></script>'
2323
).format(chunk['url'], attrs))
24-
elif chunk['name'].endswith('.css'):
24+
elif chunk['name'].endswith(('.css', '.css.gz')):
2525
tags.append((
2626
'<link type="text/css" href="{0}" rel="stylesheet" {1}/>'
2727
).format(chunk['url'], attrs))

0 commit comments

Comments
 (0)