File tree Expand file tree Collapse file tree 3 files changed +18
-10
lines changed
Expand file tree Collapse file tree 3 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,23 @@ STATICFILES_FINDERS = [
4343]
4444```
4545
46+ You will also need to expose your ` node_modules ` directory to Django's
47+ staticfiles finder. You may run ` npm ci --omit=dev ` prior to running
48+ ` collectstatic ` to avoid exposing your ` devDependencies ` publicly.
49+
50+ ``` python
51+ # settings.py
52+ from pathlib import Path
53+
54+ # add BASE_DIR (if not already present)
55+ BASE_DIR = Path(__file__ ).resolve().parent.parent
56+
57+ STATICFILES_DIRS = [
58+ # …
59+ BASE_DIR / " node_modules" ,
60+ ]
61+ ```
62+
4663Finally, add the import map to your base template:
4764
4865``` html
Original file line number Diff line number Diff line change @@ -42,15 +42,10 @@ def list(self, ignore_patterns):
4242 def _list (* ignore_patterns ):
4343 with (settings .BASE_DIR / "package.json" ).open () as f :
4444 package_json = json .load (f )
45-
4645 return [
4746 (path , storages .root_storage )
4847 for mod , path in utils .parse_root_package (package_json )
4948 if not matches_patterns (path , ignore_patterns )
50- ] + [
51- (path , storages .node_modules_storage )
52- for mod , path in utils .parse_dependencies (package_json )
53- if not matches_patterns (path , ignore_patterns )
5449 ]
5550
5651 @functools .cached_property
Original file line number Diff line number Diff line change @@ -17,9 +17,7 @@ def test_find(self):
1717 self .finder .find ("testapp/static/js/components/index.js" )
1818 == "testapp/static/js/components/index.js"
1919 )
20- assert self .finder .find ("lit-html/lit-html.js" , all = True ) == [
21- "lit-html/lit-html.js"
22- ]
20+ assert self .finder .find ("lit-html/lit-html.js" , all = True ) == []
2321 assert self .finder .find ("foo/bar.js" ) == []
2422
2523 def test_list (self ):
@@ -29,8 +27,6 @@ def test_list(self):
2927 "testapp/static/js/components/index.js" ,
3028 storages .root_storage ,
3129 ) in all_files
32- assert ("lit-html/lit-html.js" , storages .node_modules_storage ) in all_files
33- assert ("htmx.org/dist/htmx.min.js" , storages .node_modules_storage ) in all_files
3430
3531 def test_check (self , settings ):
3632 assert not self .finder .check ()
You can’t perform that action at this time.
0 commit comments