Skip to content

Commit

Permalink
Merge pull request #170 from bdauer/omit_type_attributes
Browse files Browse the repository at this point in the history
Removed type from link and script tags per #152
  • Loading branch information
joaopslins committed Aug 16, 2021
2 parents 729fbd8 + 51fdb28 commit 02ed722
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ WEBPACK_LOADER = {
If the bundle generates a file called `main-cf4b5fab6e00a404e0c7.js` and your STATIC_URL is `/static/`, then the `<script>` tag will look like this

```html
<script type="text/javascript" src="/static/output/bundles/main-cf4b5fab6e00a404e0c7.js"/>
<script src="/static/output/bundles/main-cf4b5fab6e00a404e0c7.js"/>
```
**NOTE:** If your webpack config outputs the bundles at the root of your `staticfiles` dir, then `BUNDLE_DIR_NAME` should be an empty string `''`, not `'/'`.
Expand Down Expand Up @@ -350,8 +350,8 @@ the function in the `webpack_loader.utils` module.
[{'url': '/static/bundles/main.js', u'path': u'/home/mike/root/projects/django-webpack-loader/tests/assets/bundles/main.js', u'name': u'main.js'},
{'url': '/static/bundles/styles.css', u'path': u'/home/mike/root/projects/django-webpack-loader/tests/assets/bundles/styles.css', u'name': u'styles.css'}]
>>> utils.get_as_tags('main')
['<script type="text/javascript" src="/static/bundles/main.js" ></script>',
'<link type="text/css" href="/static/bundles/styles.css" rel="stylesheet" />']
['<script src="/static/bundles/main.js" ></script>',
'<link href="/static/bundles/styles.css" rel="stylesheet" />']
```
## How to use in Production
Expand Down
12 changes: 6 additions & 6 deletions tests/app/tests/test_webpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ def test_templatetags(self):
view = TemplateView.as_view(template_name='home.html')
request = self.factory.get('/')
result = view(request)
self.assertIn('<link type="text/css" href="/static/django_webpack_loader_bundles/main.css" rel="stylesheet" />', result.rendered_content)
self.assertIn('<script type="text/javascript" src="/static/django_webpack_loader_bundles/main.js" async charset="UTF-8"></script>', result.rendered_content)
self.assertIn('<link href="/static/django_webpack_loader_bundles/main.css" rel="stylesheet" />', result.rendered_content)
self.assertIn('<script src="/static/django_webpack_loader_bundles/main.js" async charset="UTF-8"></script>', result.rendered_content)

self.assertIn('<link type="text/css" href="/static/django_webpack_loader_bundles/app2.css" rel="stylesheet" />', result.rendered_content)
self.assertIn('<script type="text/javascript" src="/static/django_webpack_loader_bundles/app2.js" ></script>', result.rendered_content)
self.assertIn('<link href="/static/django_webpack_loader_bundles/app2.css" rel="stylesheet" />', result.rendered_content)
self.assertIn('<script src="/static/django_webpack_loader_bundles/app2.js" ></script>', result.rendered_content)
self.assertIn('<img src="/static/my-image.png"/>', result.rendered_content)

view = TemplateView.as_view(template_name='only_files.html')
Expand Down Expand Up @@ -173,8 +173,8 @@ def test_jinja2(self):
with self.settings(**settings):
request = self.factory.get('/')
result = view(request)
self.assertIn('<link type="text/css" href="/static/django_webpack_loader_bundles/main.css" rel="stylesheet" />', result.rendered_content)
self.assertIn('<script type="text/javascript" src="/static/django_webpack_loader_bundles/main.js" async charset="UTF-8"></script>', result.rendered_content)
self.assertIn('<link href="/static/django_webpack_loader_bundles/main.css" rel="stylesheet" />', result.rendered_content)
self.assertIn('<script src="/static/django_webpack_loader_bundles/main.js" async charset="UTF-8"></script>', result.rendered_content)

def test_reporting_errors(self):
self.compile_bundles('webpack.config.error.js')
Expand Down
4 changes: 2 additions & 2 deletions webpack_loader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def get_as_tags(bundle_name, extension=None, config='DEFAULT', attrs=''):
for chunk in bundle:
if chunk['name'].endswith(('.js', '.js.gz')):
tags.append((
'<script type="text/javascript" src="{0}" {1}></script>'
'<script src="{0}" {1}></script>'
).format(chunk['url'], attrs))
elif chunk['name'].endswith(('.css', '.css.gz')):
tags.append((
'<link type="text/css" href="{0}" rel="stylesheet" {1}/>'
'<link href="{0}" rel="stylesheet" {1}/>'
).format(chunk['url'], attrs))
return tags

Expand Down

0 comments on commit 02ed722

Please sign in to comment.