質問編集履歴
1
ビルド環境で関係ありそうな部分を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -37,6 +37,47 @@
|
|
37
37
|
Uncaught Error: Cannot find module './rsrc/hoge.svg'
|
38
38
|
```
|
39
39
|
|
40
|
+
# ビルド環境
|
41
|
+
package.json
|
42
|
+
```json
|
43
|
+
{
|
44
|
+
"dependencies": {
|
45
|
+
"react": "^16.8.6",
|
46
|
+
"react-dom": "^16.8.6",
|
47
|
+
},
|
48
|
+
"devDependencies": {
|
49
|
+
"react-svg-loader": "^3.0.3",
|
50
|
+
"ts-loader": "^5.3.3",
|
51
|
+
"typescript": "^3.4.1",
|
52
|
+
"webpack": "^4.29.6",
|
53
|
+
}
|
54
|
+
}
|
55
|
+
```
|
56
|
+
|
57
|
+
webpack.js
|
58
|
+
```javascript
|
59
|
+
module.exports = {
|
60
|
+
module: {
|
61
|
+
rules: [
|
62
|
+
{
|
63
|
+
test: /.tsx?$/,
|
64
|
+
use: {
|
65
|
+
loader: "ts-loader",
|
66
|
+
options: {
|
67
|
+
transpileOnly: true
|
68
|
+
}
|
69
|
+
},
|
70
|
+
exclude: /node_modules/
|
71
|
+
},
|
72
|
+
{
|
73
|
+
test: /.svg$/,
|
74
|
+
use: ["react-svg-loader"]
|
75
|
+
}
|
76
|
+
]
|
77
|
+
},
|
78
|
+
};
|
79
|
+
```
|
80
|
+
|
40
81
|
# その他補足
|
41
82
|
`const SVG = React.lazy(() => import(src));`の行で直接パスを書くと正常に動作します。
|
42
83
|
例:`const SVG = React.lazy(() => import("./rsrc/hoge.svg"));`
|