Completed
Branch vue-dev (285fcd)
by Seth
41s
created

utils.js ➔ ???   A

Complexity

Conditions 1
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 17
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
A utils.js ➔ ... ➔ ??? 0 13 2
1
'use strict'
2
const path = require('path')
3
const config = require('../config')
4
const ExtractTextPlugin = require('extract-text-webpack-plugin')
5
const packageConfig = require('../package.json')
6
7
exports.assetsPath = function (_path) {
8
  const assetsSubDirectory = process.env.NODE_ENV === 'production'
9
    ? config.build.assetsSubDirectory
10
    : config.dev.assetsSubDirectory
11
12
  return path.posix.join(assetsSubDirectory, _path)
13
}
14
15
exports.cssLoaders = function (options) {
16
  options = options || {}
17
18
  const cssLoader = {
19
    loader: 'css-loader',
20
    options: {
21
      sourceMap: options.sourceMap
22
    }
23
  }
24
25
  const postcssLoader = {
26
    loader: 'postcss-loader',
27
    options: {
28
      sourceMap: options.sourceMap
29
    }
30
  }
31
32
  // generate loader string to be used with extract text plugin
33
  function generateLoaders (loader, loaderOptions) {
34
    const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]
35
36
    if (loader) {
37
      loaders.push({
38
        loader: loader + '-loader',
39
        options: Object.assign({}, loaderOptions, {
40
          sourceMap: options.sourceMap
41
        })
42
      })
43
    }
44
45
    // Extract CSS when that option is specified
46
    // (which is the case during production build)
47
    if (options.extract) {
48
      return ExtractTextPlugin.extract({
49
        use: loaders,
50
        fallback: 'vue-style-loader'
51
      })
52
    } else {
53
      return ['vue-style-loader'].concat(loaders)
54
    }
55
  }
56
57
  // https://vue-loader.vuejs.org/en/configurations/extract-css.html
58
  return {
59
    css: generateLoaders(),
60
    postcss: generateLoaders(),
61
    less: generateLoaders('less'),
62
    sass: generateLoaders('sass', { indentedSyntax: true }),
63
    scss: generateLoaders('sass'),
64
    stylus: generateLoaders('stylus'),
65
    styl: generateLoaders('stylus')
66
  }
67
}
68
69
// Generate loaders for standalone style files (outside of .vue)
70
exports.styleLoaders = function (options) {
71
  const output = []
72
  const loaders = exports.cssLoaders(options)
73
74
  for (const extension in loaders) {
75
    const loader = loaders[extension]
76
    output.push({
77
      test: new RegExp('\\.' + extension + '$'),
78
      use: loader
79
    })
80
  }
81
82
  return output
83
}
84
85
exports.createNotifierCallback = () => {
86
  const notifier = require('node-notifier')
87
88
  return (severity, errors) => {
89
    if (severity !== 'error') return
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
90
91
    const error = errors[0]
92
    const filename = error.file && error.file.split('!').pop()
93
94
    notifier.notify({
95
      title: packageConfig.name,
96
      message: severity + ': ' + error.name,
97
      subtitle: filename || '',
98
      icon: path.join(__dirname, 'logo.png')
99
    })
100
  }
101
}
102