Skip to content

Commit 2e7ab7f

Browse files
committed
Fixed support for css files. Added test case for css files.
1 parent 834b563 commit 2e7ab7f

File tree

8 files changed

+17
-2
lines changed

8 files changed

+17
-2
lines changed

tests/app/tests/test_webpack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def setUp(self):
2323
def clean_dir(self, directory):
2424
if os.path.exists(BUNDLE_PATH):
2525
[os.remove(os.path.join(BUNDLE_PATH, F)) for F in os.listdir(BUNDLE_PATH)]
26+
os.remove(settings.WEBPACK_LOADER['STATS_FILE'])
2627

2728
def compile_bundles(self, config, wait=None):
2829
if wait:
@@ -72,6 +73,7 @@ def test_simple(self):
7273

7374
main = chunks['main']
7475
self.assertEqual(main[0]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/main.js'))
76+
self.assertEqual(main[1]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/styles.css'))
7577

7678
def test_multiple_files(self):
7779
self.compile_bundles('webpack.config.split.js')

tests/assets/js/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var React = require('react');
22
var App = require('./app');
3+
var style = require('./style.css');
34

45
React.render(<App/>, document.getElementById('react-app'));

tests/assets/js/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: #e3e2e1;
3+
}

tests/assets/webpack-stats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"status":"compiling"}
1+
{"status":"done","chunks":{"main":[{"name":"main.js","path":"/home/owais/Projects/django-webpack-loader/tests/assets/bundles/main.js"},{"name":"styles.css","path":"/home/owais/Projects/django-webpack-loader/tests/assets/bundles/styles.css"}]}}

tests/assets/webpack.config.simple.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var path = require("path");
22
var webpack = require('webpack');
33
var BundleTracker = require('webpack-bundle-tracker');
4+
var ExtractTextPlugin = require("extract-text-webpack-plugin");
45

56

67
module.exports = {
@@ -12,13 +13,15 @@ module.exports = {
1213
},
1314

1415
plugins: [
16+
new ExtractTextPlugin("styles.css"),
1517
new BundleTracker({filename: './assets/webpack-stats.json'}),
1618
],
1719

1820
module: {
1921
loaders: [
2022
// we pass the output from babel loader to react-hot loader
2123
{ test: /\.jsx?$/, exclude: /node_modules/, loaders: ['babel'], },
24+
{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }
2225
],
2326
},
2427

tests/assets/webpack.config.split.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var path = require("path");
22
var webpack = require('webpack');
33
var BundleTracker = require('webpack-bundle-tracker');
44
var SplitByPathPlugin = require('webpack-split-by-path');
5+
var ExtractTextPlugin = require("extract-text-webpack-plugin");
56

67

78
module.exports = {
@@ -14,6 +15,7 @@ module.exports = {
1415
},
1516

1617
plugins: [
18+
new ExtractTextPlugin("styles.css"),
1719
new BundleTracker({filename: './assets/webpack-stats.json'}),
1820
new SplitByPathPlugin([
1921
{
@@ -27,6 +29,7 @@ module.exports = {
2729
loaders: [
2830
// we pass the output from babel loader to react-hot loader
2931
{ test: /\.jsx?$/, exclude: /node_modules/, loaders: ['babel'], },
32+
{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }
3033
],
3134
},
3235

tests/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
"babel": "^5.4.7",
1010
"babel-core": "^5.4.7",
1111
"babel-loader": "^5.1.3",
12+
"css-loader": "^0.14.1",
13+
"extract-text-webpack-plugin": "^0.8.0",
1214
"node-libs-browser": "^0.5.0",
1315
"react": "^0.13.3",
16+
"style-loader": "^0.12.3",
1417
"webpack": "^1.9.8",
1518
"webpack-bundle-tracker": "0.0.5",
1619
"webpack-dev-server": "^1.9.0",

webpack_loader/templatetags/webpack_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def render_bundle(bundle_name):
1212
bundle = get_bundle(bundle_name)
1313
tags = []
1414
for chunk in bundle:
15+
url = chunk.get('publicPath') or chunk['url']
1516
if chunk['name'].endswith('.js'):
16-
url = chunk.get('publicPath') or chunk['url']
1717
tags.append('<script type="text/javascript" src="{}"></script>'.format(url))
1818
elif chunk['name'].endswith('.css'):
1919
tags.append('<link type="text/css" href="{}" rel="stylesheet">'.format(url))

0 commit comments

Comments
 (0)