'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const fs = require('fs')
const path = require('path')
const webpack = require('webpack')
 
const {
  getPlatformScss,
  getPlatformSass,
  nvueCssPreprocessOptions
} = require('@dcloudio/uni-cli-shared')
 
const nvueStyleLoader = {
  loader: '@dcloudio/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/style'
}
 
const preprocessLoader = {
  loader: '@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader',
  options: nvueCssPreprocessOptions
}
 
const options = {
  sourceMap: false
}
const plugins = [
  require('postcss-import')({
    resolve (id, basedir, importOptions) {
      if (id.startsWith('~@/')) {
        return path.resolve(process.env.UNI_INPUT_DIR, id.substr(3))
      } else if (id.startsWith('@/')) {
        return path.resolve(process.env.UNI_INPUT_DIR, id.substr(2))
      } else if (id.startsWith('/') && !id.startsWith('//')) {
        return path.resolve(process.env.UNI_INPUT_DIR, id.substr(1))
      }
      return id
    }
  }),
  require('@dcloudio/vue-cli-plugin-uni/packages/postcss')
]
if (webpack.version[0] > 4) {
  options.postcssOptions = { plugins }
} else {
  options.parser = require('postcss-comment')
  options.plugins = plugins
}
const postcssLoader = {
  loader: 'postcss-loader',
  options
}
 
// sass 全局变量
const isSass = fs.existsSync(path.resolve(process.env.UNI_INPUT_DIR, 'uni.sass'))
const isScss = fs.existsSync(path.resolve(process.env.UNI_INPUT_DIR, 'uni.scss'))
let sassData = isSass ? getPlatformSass() : getPlatformScss()
 
if (isSass) {
  sassData = '@import "@/uni.sass"'
} else if (isScss) {
  sassData = `${sassData}
  @import "@/uni.scss";`
}
 
const scssLoader = {
  loader: '@dcloudio/vue-cli-plugin-uni/packages/sass-loader',
  options: {
    nvue: true,
    sourceMap: false
  }
}
 
const sassLoader = {
  loader: '@dcloudio/vue-cli-plugin-uni/packages/sass-loader',
  options: {
    nvue: true,
    sourceMap: false
  }
}
 
scssLoader.options.prependData = sassData
scssLoader.options.sassOptions = {
  outputStyle: 'expanded'
}
 
sassLoader.options.prependData = sassData
sassLoader.options.sassOptions = {
  outputStyle: 'expanded',
  indentedSyntax: true
}
 
const lessLoader = {
  loader: 'less-loader',
  options: {
    sourceMap: false
  }
}
 
const stylusLoader = {
  loader: 'stylus-loader',
  options: {
    sourceMap: false,
    preferPathResolver: 'webpack'
  }
}
 
function createOneOf (preLoader) {
  const use = [
    nvueStyleLoader,
    preprocessLoader
  ]
  use.push(postcssLoader)
  if (preLoader) {
    use.push(preLoader)
  }
  use.push(preprocessLoader)
 
  return [{
    resourceQuery: /\?vue/,
    use
  },
  {
    use
  }
  ]
}
 
module.exports = [{
  test: /\.css$/,
  oneOf: createOneOf()
}, {
  test: /\.scss$/,
  oneOf: createOneOf(scssLoader)
}, {
  test: /\.sass$/,
  oneOf: createOneOf(sassLoader)
}, {
  test: /\.less$/,
  oneOf: createOneOf(lessLoader)
}, {
  test: /\.styl(us)?$/,
  oneOf: createOneOf(stylusLoader)
}]