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 = [
43
43
]
44
44
```
45
45
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
+
46
63
Finally, add the import map to your base template:
47
64
48
65
``` html
Original file line number Diff line number Diff line change @@ -42,15 +42,10 @@ def list(self, ignore_patterns):
42
42
def _list (* ignore_patterns ):
43
43
with (settings .BASE_DIR / "package.json" ).open () as f :
44
44
package_json = json .load (f )
45
-
46
45
return [
47
46
(path , storages .root_storage )
48
47
for mod , path in utils .parse_root_package (package_json )
49
48
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 )
54
49
]
55
50
56
51
@functools .cached_property
Original file line number Diff line number Diff line change @@ -17,9 +17,7 @@ def test_find(self):
17
17
self .finder .find ("testapp/static/js/components/index.js" )
18
18
== "testapp/static/js/components/index.js"
19
19
)
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 ) == []
23
21
assert self .finder .find ("foo/bar.js" ) == []
24
22
25
23
def test_list (self ):
@@ -29,8 +27,6 @@ def test_list(self):
29
27
"testapp/static/js/components/index.js" ,
30
28
storages .root_storage ,
31
29
) 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
34
30
35
31
def test_check (self , settings ):
36
32
assert not self .finder .check ()
You can’t perform that action at this time.
0 commit comments