forked from Nothing-Works/vuetifyjs-mix-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
111 lines (87 loc) · 2.88 KB
/
index.js
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
const mix = require('laravel-mix')
const getPath = require('./src/getPath')
const resolveOptions = require('./src/resolveOptions')
class Vuetify {
constructor() {
this.vuetifyPath = getPath('node_modules/vuetify')
}
withVuetifyLoader() {
return this.vuetifyLoader === 'vuetify-loader'
}
withExtract() {
return !!this.extract
}
withPostcss() {
return !!this.postcss
}
register(loader, ...options) {
this.vuetifyLoader = loader
this.resolve(options)
}
resolve(options) {
const resolved = resolveOptions(options)
this.vuetifyLoaderOptions = resolved.vuetifyLoaderOptions
this.sassArray = resolved.sassArray
this.extract = resolved.extract
this.postcss = resolved.postcss
}
dependencies() {
this.requiresReload = true
const deps = ['vuetify', 'sass', 'sass-loader', 'deepmerge']
if (this.withVuetifyLoader()) deps.push('vuetify-loader@next')
if (this.withExtract()) deps.push('mini-css-extract-plugin')
if (this.withPostcss()) deps.push('postcss-loader')
return deps
}
generateRules() {
return this.sassArray.map((t) => ({
test: t.sass,
include: [this.vuetifyPath],
use: [
this.withExtract()
? require('mini-css-extract-plugin').loader
: 'vue-style-loader',
'css-loader',
...this.addPostcssIfNeeded(),
{
loader: 'sass-loader',
options: {
additionalData: t.data,
implementation: require('sass'),
sassOptions: {
indentedSyntax: true
}
}
}
]
}))
}
webpackRules() {
return this.generateRules()
}
webpackConfig(config) {
this.excludeVuetifyPath(config)
if (this.withVuetifyLoader()) this.addVuetifyLoader(config)
if (this.withExtract()) this.addExtract(config)
}
addPostcssIfNeeded() {
return this.withPostcss() ? ['postcss-loader'] : []
}
addVuetifyLoader(config) {
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')
config.plugins.push(new VuetifyLoaderPlugin(this.vuetifyLoaderOptions))
}
addExtract(config) {
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
config.plugins.push(
new MiniCssExtractPlugin({ filename: this.extract })
)
}
excludeVuetifyPath(config) {
for (const i of this.sassArray)
config.module.rules
.find((r) => String(r.test) === String(i.sass))
.exclude.push(this.vuetifyPath)
}
}
mix.extend('vuetify', new Vuetify())