質問編集履歴

3

/build/webpack.base.conf.jsの追加

2020/08/13 03:47

投稿

reppeppepper
reppeppepper

スコア4

test CHANGED
File without changes
test CHANGED
@@ -427,3 +427,197 @@
427
427
  module.exports = webpackConfig
428
428
 
429
429
  ```
430
+
431
+
432
+
433
+ /build/webpack.base.conf.jsの中身
434
+
435
+ ```
436
+
437
+ 'use strict'
438
+
439
+ const path = require('path')
440
+
441
+ const utils = require('./utils')
442
+
443
+ const config = require('../config')
444
+
445
+ const vueLoaderConfig = require('./vue-loader.conf')
446
+
447
+
448
+
449
+ function resolve (dir) {
450
+
451
+ return path.join(__dirname, '..', dir)
452
+
453
+ }
454
+
455
+
456
+
457
+ const createLintingRule = () => ({
458
+
459
+ test: /.(js|vue)$/,
460
+
461
+ loader: 'eslint-loader',
462
+
463
+ enforce: 'pre',
464
+
465
+ include: [resolve('src'), resolve('test')],
466
+
467
+ options: {
468
+
469
+ formatter: require('eslint-friendly-formatter'),
470
+
471
+ emitWarning: !config.dev.showEslintErrorsInOverlay
472
+
473
+ }
474
+
475
+ })
476
+
477
+
478
+
479
+ module.exports = {
480
+
481
+ context: path.resolve(__dirname, '../'),
482
+
483
+ entry: {
484
+
485
+ app: './src/main.js'
486
+
487
+ },
488
+
489
+ output: {
490
+
491
+ path: config.build.assetsRoot,
492
+
493
+ filename: '[name].js',
494
+
495
+ publicPath: process.env.NODE_ENV === 'production'
496
+
497
+ ? config.build.assetsPublicPath
498
+
499
+ : config.dev.assetsPublicPath
500
+
501
+ },
502
+
503
+ resolve: {
504
+
505
+ extensions: ['.js', '.vue', '.json'],
506
+
507
+ alias: {
508
+
509
+ 'vue$': 'vue/dist/vue.esm.js',
510
+
511
+ '@': resolve('src'),
512
+
513
+ }
514
+
515
+ },
516
+
517
+ module: {
518
+
519
+ rules: [
520
+
521
+ ...(config.dev.useEslint ? [createLintingRule()] : []),
522
+
523
+ {
524
+
525
+ test: /.vue$/,
526
+
527
+ loader: 'vue-loader',
528
+
529
+ options: vueLoaderConfig
530
+
531
+ },
532
+
533
+ {
534
+
535
+ test: /.js$/,
536
+
537
+ loader: 'babel-loader',
538
+
539
+ include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
540
+
541
+ },
542
+
543
+ {
544
+
545
+ test: /.(png|jpe?g|gif|svg)(?.*)?$/,
546
+
547
+ loader: 'url-loader',
548
+
549
+ options: {
550
+
551
+ limit: 10000,
552
+
553
+ name: utils.assetsPath('img/[name].[hash:7].[ext]')
554
+
555
+ }
556
+
557
+ },
558
+
559
+ {
560
+
561
+ test: /.(mp4|webm|ogg|mp3|wav|flac|aac)(?.*)?$/,
562
+
563
+ loader: 'url-loader',
564
+
565
+ options: {
566
+
567
+ limit: 10000,
568
+
569
+ name: utils.assetsPath('media/[name].[hash:7].[ext]')
570
+
571
+ }
572
+
573
+ },
574
+
575
+ {
576
+
577
+ test: /.(woff2?|eot|ttf|otf)(?.*)?$/,
578
+
579
+ loader: 'url-loader',
580
+
581
+ options: {
582
+
583
+ limit: 10000,
584
+
585
+ name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
586
+
587
+ }
588
+
589
+ }
590
+
591
+ ]
592
+
593
+ },
594
+
595
+ node: {
596
+
597
+ // prevent webpack from injecting useless setImmediate polyfill because Vue
598
+
599
+ // source contains it (although only uses it if it's native).
600
+
601
+ setImmediate: false,
602
+
603
+ // prevent webpack from injecting mocks to Node native modules
604
+
605
+ // that does not make sense for the client
606
+
607
+ dgram: 'empty',
608
+
609
+ fs: 'empty',
610
+
611
+ net: 'empty',
612
+
613
+ tls: 'empty',
614
+
615
+ child_process: 'empty'
616
+
617
+ }
618
+
619
+ }
620
+
621
+
622
+
623
+ ```

2

/build/webpack.test.conf.jsの中身の追加

2020/08/13 03:47

投稿

reppeppepper
reppeppepper

スコア4

test CHANGED
File without changes
test CHANGED
@@ -355,3 +355,75 @@
355
355
  }
356
356
 
357
357
  ```
358
+
359
+
360
+
361
+ /build/webpack.test.conf.jsの中身
362
+
363
+ ```
364
+
365
+ 'use strict'
366
+
367
+ // This is the webpack config used for unit tests.
368
+
369
+
370
+
371
+ const utils = require('./utils')
372
+
373
+ const webpack = require('webpack')
374
+
375
+ const merge = require('webpack-merge')
376
+
377
+ const baseWebpackConfig = require('./webpack.base.conf')
378
+
379
+
380
+
381
+ const webpackConfig = merge(baseWebpackConfig, {
382
+
383
+ // use inline sourcemap for karma-sourcemap-loader
384
+
385
+ module: {
386
+
387
+ rules: utils.styleLoaders()
388
+
389
+ },
390
+
391
+ devtool: '#inline-source-map',
392
+
393
+ resolveLoader: {
394
+
395
+ alias: {
396
+
397
+ // necessary to to make lang="scss" work in test when using vue-loader's ?inject option
398
+
399
+ // see discussion at https://github.com/vuejs/vue-loader/issues/724
400
+
401
+ 'scss-loader': 'sass-loader'
402
+
403
+ }
404
+
405
+ },
406
+
407
+ plugins: [
408
+
409
+ new webpack.DefinePlugin({
410
+
411
+ 'process.env': require('../config/test.env')
412
+
413
+ })
414
+
415
+ ]
416
+
417
+ })
418
+
419
+
420
+
421
+ // no need for app entry during tests
422
+
423
+ delete webpackConfig.entry
424
+
425
+
426
+
427
+ module.exports = webpackConfig
428
+
429
+ ```

1

/test/unit/karma.conf.jsの中身を追加

2020/08/13 03:42

投稿

reppeppepper
reppeppepper

スコア4

test CHANGED
File without changes
test CHANGED
@@ -275,3 +275,83 @@
275
275
 
276
276
 
277
277
  ```
278
+
279
+
280
+
281
+ /test/unit/karma.conf.jsの中身
282
+
283
+ ```
284
+
285
+ // This is a karma config file. For more details see
286
+
287
+ // http://karma-runner.github.io/0.13/config/configuration-file.html
288
+
289
+ // we are also using it with karma-webpack
290
+
291
+ // https://github.com/webpack/karma-webpack
292
+
293
+
294
+
295
+ var webpackConfig = require('../../build/webpack.test.conf')
296
+
297
+
298
+
299
+ module.exports = function karmaConfig (config) {
300
+
301
+ config.set({
302
+
303
+ // to run in additional browsers:
304
+
305
+ // 1. install corresponding karma launcher
306
+
307
+ // http://karma-runner.github.io/0.13/config/browsers.html
308
+
309
+ // 2. add it to the `browsers` array below.
310
+
311
+ browsers: ['PhantomJS'],
312
+
313
+ frameworks: ['mocha', 'sinon-chai', 'phantomjs-shim'],
314
+
315
+ reporters: ['spec', 'coverage'],
316
+
317
+ files: [
318
+
319
+ '../../node_modules/es6-promise/dist/es6-promise.auto.js',
320
+
321
+ './index.js'
322
+
323
+ ],
324
+
325
+ preprocessors: {
326
+
327
+ './index.js': ['webpack', 'sourcemap']
328
+
329
+ },
330
+
331
+ webpack: webpackConfig,
332
+
333
+ webpackMiddleware: {
334
+
335
+ noInfo: true
336
+
337
+ },
338
+
339
+ coverageReporter: {
340
+
341
+ dir: './coverage',
342
+
343
+ reporters: [
344
+
345
+ { type: 'lcov', subdir: '.' },
346
+
347
+ { type: 'text-summary' }
348
+
349
+ ]
350
+
351
+ }
352
+
353
+ })
354
+
355
+ }
356
+
357
+ ```