説明なし

utils.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var path = require('path')
  2. var config = require('../config')
  3. var ExtractTextPlugin = require('extract-text-webpack-plugin')
  4. exports.assetsPath = function (_path) {
  5. var assetsSubDirectory = process.env.NODE_ENV === 'production'
  6. ? config.build.assetsSubDirectory
  7. : config.dev.assetsSubDirectory
  8. return path.posix.join(assetsSubDirectory, _path)
  9. }
  10. exports.cssLoaders = function (options) {
  11. options = options || {}
  12. var cssLoader = {
  13. loader: 'css-loader',
  14. options: {
  15. minimize: process.env.NODE_ENV === 'production',
  16. sourceMap: options.sourceMap
  17. }
  18. }
  19. // generate loader string to be used with extract text plugin
  20. function generateLoaders (loader, loaderOptions) {
  21. var loaders = [cssLoader]
  22. if (loader) {
  23. loaders.push({
  24. loader: loader + '-loader',
  25. options: Object.assign({}, loaderOptions, {
  26. sourceMap: options.sourceMap
  27. })
  28. })
  29. }
  30. // Extract CSS when that option is specified
  31. // (which is the case during production build)
  32. if (options.extract) {
  33. return ExtractTextPlugin.extract({
  34. use: loaders,
  35. fallback: 'vue-style-loader'
  36. })
  37. } else {
  38. return ['vue-style-loader'].concat(loaders)
  39. }
  40. }
  41. // https://vue-loader.vuejs.org/en/configurations/extract-css.html
  42. return {
  43. css: generateLoaders(),
  44. postcss: generateLoaders(),
  45. less: generateLoaders('less'),
  46. sass: generateLoaders('sass', { indentedSyntax: true }),
  47. scss: generateLoaders('sass'),
  48. stylus: generateLoaders('stylus'),
  49. styl: generateLoaders('stylus')
  50. }
  51. }
  52. // Generate loaders for standalone style files (outside of .vue)
  53. exports.styleLoaders = function (options) {
  54. var output = []
  55. var loaders = exports.cssLoaders(options)
  56. for (var extension in loaders) {
  57. var loader = loaders[extension]
  58. output.push({
  59. test: new RegExp('\\.' + extension + '$'),
  60. use: loader
  61. })
  62. }
  63. return output
  64. }