微小悟公众号管理系统

utils.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. var path = require('path')
  2. var chalk = require('chalk')
  3. var config = require('../config')
  4. var ExtractTextPlugin = require('extract-text-webpack-plugin')
  5. // var saladConf = require('./webpack.salad.conf.json')
  6. // var postcssSalad = require('postcss-salad')
  7. exports.assetsPath = function (_path) {
  8. var assetsSubDirectory = process.env.NODE_ENV === 'production'
  9. ? config.build.assetsSubDirectory
  10. : config.dev.assetsSubDirectory
  11. return path.posix.join(assetsSubDirectory, _path)
  12. }
  13. exports.cssLoaders = function (options) {
  14. options = options || {}
  15. var cssLoader = {
  16. loader: 'css-loader',
  17. options: {
  18. minimize: process.env.NODE_ENV === 'production',
  19. sourceMap: options.sourceMap
  20. }
  21. }
  22. // generate loader string to be used with extract text plugin
  23. function generateLoaders (loader, loaderOptions) {
  24. var loaders = [cssLoader]
  25. var isSass = loader === 'sass'
  26. var isCss = loader === 'css'
  27. if (loader) {
  28. if (isSass) {
  29. loaders.push({
  30. loader: 'postcss-loader',
  31. options: {
  32. sourceMap: options.sourceMap,
  33. config: {
  34. path: '.postcssrc.js'
  35. }
  36. }
  37. })
  38. }
  39. loaders.push({
  40. loader: loader + '-loader',
  41. options: Object.assign({}, loaderOptions, {
  42. sourceMap: options.sourceMap
  43. })
  44. })
  45. }
  46. // Extract CSS when that option is specified
  47. // (which is the case during production build)
  48. if (options.extract || isCss) {
  49. return ExtractTextPlugin.extract({
  50. use: loaders,
  51. fallback: 'vue-style-loader',
  52. publicPath: '../../../'
  53. })
  54. } else {
  55. return ['vue-style-loader'].concat(loaders)
  56. }
  57. }
  58. // https://vue-loader.vuejs.org/en/configurations/extract-css.html
  59. return {
  60. css: generateLoaders(),
  61. postcss: generateLoaders(),
  62. less: generateLoaders('less'),
  63. sass: generateLoaders('sass', { indentedSyntax: true }),
  64. scss: generateLoaders('sass'),
  65. stylus: generateLoaders('stylus'),
  66. styl: generateLoaders('stylus')
  67. }
  68. }
  69. // Generate loaders for standalone style files (outside of .vue)
  70. exports.styleLoaders = function (options) {
  71. var output = []
  72. var loaders = exports.cssLoaders(options)
  73. for (var extension in loaders) {
  74. var loader = loaders[extension]
  75. output.push({
  76. test: new RegExp('\\.' + extension + '$'),
  77. use: loader
  78. })
  79. }
  80. return output
  81. }
  82. exports.copyright = function() {
  83. console.log(chalk.blue(`
  84. ████████ ████████ ██████████████ ██████████████
  85. ██░░░░██ ██░░░░██ ██░░░░░░░░░░██ ██░░░░░░░░░░██
  86. ████░░██ ██░░████ ██░░██████████ ██░░██████████
  87. ██░░░░██░░░░██ ██░░██ ██░░██
  88. ████░░░░░░████ ██░░██████████ ██░░██████████
  89. ████░░████ ██░░░░░░░░░░██ ██░░░░░░░░░░██
  90. ██░░██ ██░░██████████ ██░░██████████
  91. ██░░██ ██░░██ ██░░██
  92. ██░░██ ██░░██ ██░░██████████
  93. ██░░██ ██░░██ ██░░░░░░░░░░██
  94. ██████ ██████ ██████████████
  95. ♥ Yowant FrontEnd Team ♥
  96. `))
  97. }
  98. exports.clog = function(color, str) {
  99. console.log(chalk[color](str))
  100. }