Commit 7bec574
committed
bug #536 Fix JSON files support in Encore.copyFiles() (Lyrkan)
This PR was merged into the master branch.
Discussion
----------
Fix JSON files support in Encore.copyFiles()
This PR fixes #535.
As explained in the issue, the current version doesn't allow `Encore.copyFiles()` to process JSON files because of how Webpack 4 handles them.
Basically, from what I understand, for most of the files it works that way:
```
Imported file (module.type = javascript/auto)
=> file-loader (takes anything, returns JS content)
=> Webpack JS parser
```
But for `.json` files the JS parser is replaced by a JSON parser:
```
Imported file (module.type = json)
=> file-loader (takes anything, returns JS content)
=> Webpack JSON parser
```
Since that "Webpack JSON parser" part expects JSON data (and not something that contains JS), the compilation fails at that point.
There is no way to disable that behavior when you specify loaders the "inline" way... which is what we do for `Encore.copyFiles()`, you can only do it by defining a config rule that forces the `javascript/auto` type.
What the PR does: it adds another loader in front of the file-loader that returns the input it received but after setting its `_module.type` (and the generator/parser that go with it) to `javascript/auto`.
So in the end we get:
```
Imported file (module.type = json)
=> file-loader (takes anything, returns JS content)
=> copy-files-loader (sets type to javascript/auto and returns the same content)
=> Webpack JS parser
```
Commits
-------
4ef8c2a Fix JSON files support in Encore.copyFiles()File tree
6 files changed
+87
-1
lines changed- fixtures/copy
- lib
- webpack
- test
6 files changed
+87
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
186 | 188 | | |
187 | | - | |
| 189 | + | |
188 | 190 | | |
189 | 191 | | |
190 | 192 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1891 | 1891 | | |
1892 | 1892 | | |
1893 | 1893 | | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
1894 | 1932 | | |
1895 | 1933 | | |
1896 | 1934 | | |
| |||
0 commit comments