質問編集履歴
3
追記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
【webpack】Vueコンポーネント内に記載したTypeScriptのデコレータを
|
1
|
+
【webpack】Vueコンポーネント内に記載したTypeScriptのデコレータを使えない
|
test
CHANGED
@@ -12,12 +12,26 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
## 環境
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
モジュール|バージョン
|
20
|
+
|
21
|
+
---|---
|
22
|
+
|
23
|
+
vue|^2.6.11
|
24
|
+
|
25
|
+
ts-loader|^8.0.2
|
26
|
+
|
27
|
+
typescript|^3.9.7
|
28
|
+
|
29
|
+
|
30
|
+
|
15
31
|
## エラー内容
|
16
32
|
|
17
33
|
webpackコマンドでビルドすると次のようなエラーが発生します。
|
18
34
|
|
19
|
-
エラー内容を読む限り、```@```を解析できていないと考えています。
|
20
|
-
|
21
35
|
|
22
36
|
|
23
37
|
ご共有までに、vue-property-decoratorのデコレータを使用してコンポーネントを使おうとしました。
|
@@ -26,8 +40,6 @@
|
|
26
40
|
|
27
41
|
|
28
42
|
|
29
|
-
|
30
|
-
|
31
43
|
```
|
32
44
|
|
33
45
|
ERROR in ./src/ts/components/Hello.vue?vue&type=script&lang=ts& (./node_modules/vue-loader/lib??vue-loader-options!./src/ts/components/Hello.vue?vue&type=script&lang=ts&) 11:0
|
@@ -50,6 +62,8 @@
|
|
50
62
|
|
51
63
|
```
|
52
64
|
|
65
|
+
|
66
|
+
|
53
67
|
## ソース
|
54
68
|
|
55
69
|
### webpack.config.js
|
@@ -746,8 +760,12 @@
|
|
746
760
|
|
747
761
|
### 実行したコマンド
|
748
762
|
|
763
|
+
node_module内にあるwebpackを起動して、ビルドしています。
|
764
|
+
|
749
765
|
```bash
|
750
766
|
|
751
767
|
$ npm run dev
|
752
768
|
|
769
|
+
// node_modules/webpack/bin/webpack.js --mode=development
|
770
|
+
|
753
|
-
```
|
771
|
+
```
|
2
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
|
55
55
|
### webpack.config.js
|
56
56
|
|
57
|
-
t
|
57
|
+
ts拡張子のローダー設定で、options.appendTsSuffixToにvueファイルを対象にする設定をしています。
|
58
58
|
|
59
59
|
|
60
60
|
|
1
webpackのコンフィグ追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,6 +52,432 @@
|
|
52
52
|
|
53
53
|
## ソース
|
54
54
|
|
55
|
+
### webpack.config.js
|
56
|
+
|
57
|
+
typescriptのローダーは設定しています。
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
const path = require('path');
|
64
|
+
|
65
|
+
const webpack = require('webpack');
|
66
|
+
|
67
|
+
const glob = require('glob');
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
const VueLoaderPlugin = require('vue-loader/lib/plugin');
|
72
|
+
|
73
|
+
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
78
|
+
|
79
|
+
const HtmlWebpackPugPlugin = require('html-webpack-pug-plugin');
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
const srcDir = './src';
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
/**
|
88
|
+
|
89
|
+
* ファイル名のみ抽出
|
90
|
+
|
91
|
+
*
|
92
|
+
|
93
|
+
* @param {string} path
|
94
|
+
|
95
|
+
* @return {void | BaseNode | string | *}
|
96
|
+
|
97
|
+
*/
|
98
|
+
|
99
|
+
const getFileName = function(path) {
|
100
|
+
|
101
|
+
return path.replace(/.[^/.]+$/, '');
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
const templates = [];
|
108
|
+
|
109
|
+
const srcPugDir = srcDir + '/pug';
|
110
|
+
|
111
|
+
glob.sync('**/*.pug', {
|
112
|
+
|
113
|
+
ignore: '**/_*.pug',
|
114
|
+
|
115
|
+
cwd: srcPugDir,
|
116
|
+
|
117
|
+
}).map(function(file) {
|
118
|
+
|
119
|
+
templates.push(new HtmlWebpackPlugin({
|
120
|
+
|
121
|
+
template: path.resolve(srcPugDir, file),
|
122
|
+
|
123
|
+
filename: getFileName(file) + '.html',
|
124
|
+
|
125
|
+
}));
|
126
|
+
|
127
|
+
});
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
const TerserPlugin = require('terser-webpack-plugin');
|
132
|
+
|
133
|
+
const workboxPlugin = require('workbox-webpack-plugin');
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
module.exports = {
|
138
|
+
|
139
|
+
mode: 'development',
|
140
|
+
|
141
|
+
entry: {
|
142
|
+
|
143
|
+
'index': './src/ts/index.ts',
|
144
|
+
|
145
|
+
},
|
146
|
+
|
147
|
+
output: {
|
148
|
+
|
149
|
+
path: path.resolve(__dirname, './dist'),
|
150
|
+
|
151
|
+
publicPath: '/dist/',
|
152
|
+
|
153
|
+
filename: 'build.js',
|
154
|
+
|
155
|
+
},
|
156
|
+
|
157
|
+
plugins: [
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
...templates,
|
162
|
+
|
163
|
+
new HtmlWebpackPugPlugin(),
|
164
|
+
|
165
|
+
new VueLoaderPlugin(),
|
166
|
+
|
167
|
+
new webpack.ProgressPlugin(),
|
168
|
+
|
169
|
+
new workboxPlugin.GenerateSW({
|
170
|
+
|
171
|
+
swDest: 'sw.js',
|
172
|
+
|
173
|
+
clientsClaim: true,
|
174
|
+
|
175
|
+
skipWaiting: false,
|
176
|
+
|
177
|
+
}),
|
178
|
+
|
179
|
+
],
|
180
|
+
|
181
|
+
module: {
|
182
|
+
|
183
|
+
rules: [
|
184
|
+
|
185
|
+
{
|
186
|
+
|
187
|
+
test: /.vue$/,
|
188
|
+
|
189
|
+
loader: 'vue-loader',
|
190
|
+
|
191
|
+
options: {
|
192
|
+
|
193
|
+
loaders: {
|
194
|
+
|
195
|
+
'scss': [
|
196
|
+
|
197
|
+
'vue-style-loader',
|
198
|
+
|
199
|
+
'css-loader',
|
200
|
+
|
201
|
+
'sass-loader',
|
202
|
+
|
203
|
+
],
|
204
|
+
|
205
|
+
'sass': [
|
206
|
+
|
207
|
+
'vue-style-loader',
|
208
|
+
|
209
|
+
'css-loader',
|
210
|
+
|
211
|
+
'sass-loader?indentedSyntax',
|
212
|
+
|
213
|
+
],
|
214
|
+
|
215
|
+
},
|
216
|
+
|
217
|
+
},
|
218
|
+
|
219
|
+
},
|
220
|
+
|
221
|
+
{
|
222
|
+
|
223
|
+
test: /.(ts|tsx)?$/,
|
224
|
+
|
225
|
+
loader: 'ts-loader',
|
226
|
+
|
227
|
+
include: [],
|
228
|
+
|
229
|
+
exclude: [/node_modules/],
|
230
|
+
|
231
|
+
options: {
|
232
|
+
|
233
|
+
appendTsSuffixTo: [/.vue$/],
|
234
|
+
|
235
|
+
},
|
236
|
+
|
237
|
+
},
|
238
|
+
|
239
|
+
{
|
240
|
+
|
241
|
+
test: /.(png|jpg|gif|svg)$/,
|
242
|
+
|
243
|
+
loader: 'file-loader',
|
244
|
+
|
245
|
+
options: {
|
246
|
+
|
247
|
+
name: '[name].[ext]?[hash]',
|
248
|
+
|
249
|
+
},
|
250
|
+
|
251
|
+
},
|
252
|
+
|
253
|
+
{
|
254
|
+
|
255
|
+
test: /.css$/,
|
256
|
+
|
257
|
+
use: [
|
258
|
+
|
259
|
+
'vue-style-loader',
|
260
|
+
|
261
|
+
'css-loader',
|
262
|
+
|
263
|
+
],
|
264
|
+
|
265
|
+
},
|
266
|
+
|
267
|
+
{
|
268
|
+
|
269
|
+
test: /.pug$/,
|
270
|
+
|
271
|
+
oneOf: [
|
272
|
+
|
273
|
+
{
|
274
|
+
|
275
|
+
resourceQuery: /^?vue/,
|
276
|
+
|
277
|
+
use: ['pug-plain-loader'],
|
278
|
+
|
279
|
+
},
|
280
|
+
|
281
|
+
{
|
282
|
+
|
283
|
+
use: ['raw-loader', 'pug-plain-loader'],
|
284
|
+
|
285
|
+
},
|
286
|
+
|
287
|
+
],
|
288
|
+
|
289
|
+
},
|
290
|
+
|
291
|
+
{
|
292
|
+
|
293
|
+
test: /.scss$/,
|
294
|
+
|
295
|
+
use: [
|
296
|
+
|
297
|
+
'style-loader',
|
298
|
+
|
299
|
+
{
|
300
|
+
|
301
|
+
loader: 'css-loader',
|
302
|
+
|
303
|
+
options: {
|
304
|
+
|
305
|
+
url: false,
|
306
|
+
|
307
|
+
sourceMap: true,
|
308
|
+
|
309
|
+
importLoaders: 2,
|
310
|
+
|
311
|
+
},
|
312
|
+
|
313
|
+
},
|
314
|
+
|
315
|
+
{
|
316
|
+
|
317
|
+
loader: 'postcss-loader',
|
318
|
+
|
319
|
+
options: {
|
320
|
+
|
321
|
+
sourceMap: true,
|
322
|
+
|
323
|
+
plugins: [
|
324
|
+
|
325
|
+
require('autoprefixer')({
|
326
|
+
|
327
|
+
grid: true,
|
328
|
+
|
329
|
+
}),
|
330
|
+
|
331
|
+
],
|
332
|
+
|
333
|
+
},
|
334
|
+
|
335
|
+
},
|
336
|
+
|
337
|
+
{
|
338
|
+
|
339
|
+
loader: 'sass-loader',
|
340
|
+
|
341
|
+
options: {
|
342
|
+
|
343
|
+
sourceMap: true,
|
344
|
+
|
345
|
+
},
|
346
|
+
|
347
|
+
},
|
348
|
+
|
349
|
+
'import-glob-loader',
|
350
|
+
|
351
|
+
],
|
352
|
+
|
353
|
+
},
|
354
|
+
|
355
|
+
],
|
356
|
+
|
357
|
+
},
|
358
|
+
|
359
|
+
resolve: {
|
360
|
+
|
361
|
+
extensions: ['.tsx', '.ts', '.js', '.json', '.vue'],
|
362
|
+
|
363
|
+
alias: {
|
364
|
+
|
365
|
+
'vue$': 'vue/dist/vue.esm.js',
|
366
|
+
|
367
|
+
},
|
368
|
+
|
369
|
+
},
|
370
|
+
|
371
|
+
devServer: {
|
372
|
+
|
373
|
+
contentBase: path.join(__dirname, 'dist'),
|
374
|
+
|
375
|
+
compress: true,
|
376
|
+
|
377
|
+
openPage: 'index.html',
|
378
|
+
|
379
|
+
watchContentBase: true,
|
380
|
+
|
381
|
+
inline: true,
|
382
|
+
|
383
|
+
port: 8080,
|
384
|
+
|
385
|
+
historyApiFallback: true,
|
386
|
+
|
387
|
+
noInfo: true,
|
388
|
+
|
389
|
+
},
|
390
|
+
|
391
|
+
performance: {
|
392
|
+
|
393
|
+
hints: false,
|
394
|
+
|
395
|
+
},
|
396
|
+
|
397
|
+
devtool: '#eval-source-map',
|
398
|
+
|
399
|
+
optimization: {
|
400
|
+
|
401
|
+
minimizer: [new TerserPlugin()],
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
splitChunks: {
|
406
|
+
|
407
|
+
cacheGroups: {
|
408
|
+
|
409
|
+
vendors: {
|
410
|
+
|
411
|
+
priority: -10,
|
412
|
+
|
413
|
+
test: /[\/]node_modules[\/]/,
|
414
|
+
|
415
|
+
},
|
416
|
+
|
417
|
+
},
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
chunks: 'async',
|
422
|
+
|
423
|
+
minChunks: 1,
|
424
|
+
|
425
|
+
minSize: 30000,
|
426
|
+
|
427
|
+
name: true,
|
428
|
+
|
429
|
+
},
|
430
|
+
|
431
|
+
},
|
432
|
+
|
433
|
+
};
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
// product設定
|
438
|
+
|
439
|
+
if (process.env.NODE_ENV === 'production') {
|
440
|
+
|
441
|
+
module.exports.devtool = '#source-map';
|
442
|
+
|
443
|
+
module.exports.plugins = (module.exports.plugins || []).concat([
|
444
|
+
|
445
|
+
new webpack.DefinePlugin({
|
446
|
+
|
447
|
+
'process.env': {
|
448
|
+
|
449
|
+
NODE_ENV: '"production"',
|
450
|
+
|
451
|
+
},
|
452
|
+
|
453
|
+
}),
|
454
|
+
|
455
|
+
new webpack.LoaderOptionsPlugin({
|
456
|
+
|
457
|
+
minimize: true,
|
458
|
+
|
459
|
+
}),
|
460
|
+
|
461
|
+
]);
|
462
|
+
|
463
|
+
module.exports.optimization.minimizer =
|
464
|
+
|
465
|
+
(module.exports.optimization.minimizer || []).concat([
|
466
|
+
|
467
|
+
new UglifyJsPlugin({
|
468
|
+
|
469
|
+
sourceMap: true,
|
470
|
+
|
471
|
+
}),
|
472
|
+
|
473
|
+
]);
|
474
|
+
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
```
|
480
|
+
|
55
481
|
### tsconfig.json
|
56
482
|
|
57
483
|
デコレータを有効にするために、```experimentalDecorators```は有効にしています。
|