-
Notifications
You must be signed in to change notification settings - Fork 12
/
DeviseMix.js
255 lines (229 loc) · 6.45 KB
/
DeviseMix.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
let mix = require('laravel-mix');
let webpack = require('webpack');
let glob = require('glob-all');
let purgeCss = require('purgecss-webpack-plugin')
const config = require('./config')
const vueLoaderConfig = require('./vue-loader.conf')
const utils = require('./utils')
var env = require('./config/dev.env')
if (mix.inProduction()) {
env = require('./config/prod.env')
}
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const WebpackLaravelMixManifest = require('webpack-laravel-mix-manifest').default;
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
class DeviseMix {
/**
* All dependencies that should be installed by Mix.
*
* @return {Array}
*/
dependencies() {
// Example:
// return ['typeScript', 'ts'];
}
/**
* Register the component.
*
* When your component is called, all user parameters
* will be passed to this method.
*
* Ex: register(src, output) {}
* Ex: mix.yourPlugin('src/path', 'output/path');
*
* @param {*} ...params
* @return {void}
*
*/
register(params) {
// Example:
// this.config = { proxy: arg };
}
/**
* Boot the component. This method is triggered after the
* user's webpack.mix.js file has executed.
*/
boot() {
// Example:
// if (Config.options.foo) {}
}
/**
* Append to the master Mix webpack entry object.
*
* @param {Entry} entry
* @return {void}
*/
webpackEntry(entry) {
}
/**
* Rules to be merged with the master webpack loaders.
*
* @return {Array|Object}
*/
webpackRules() {
return [
// {
// test: /\.vue$/,
// loader: 'vue-loader',
// exclude: /bower_components/,
// options: {
// extractCSS: new ExtractTextPlugin("style.css"),
// config: {
// path: '../vue/src/tailwind/tailwind.js'
// }
// }
// }
// {
// test: /devise\.s[ac]ss$/,
// loaders: [ 'style-loader', 'css-loader', 'sass-loader' ]
// },
// {
// test: /devise\.s[ac]ss$/,
// use: ExtractTextPlugin.extract({
// fallback: 'style-loader',
// use: [
// { loader: 'css-loader', options: { importLoaders: 1 } },
// 'postcss-loader'
// ]
// })
// }
]
}
/*
* Plugins to be merged with the master webpack config.
*
* @return {Array|Object}
*/
webpackPlugins() {
// Example:
// return new webpack.ProvidePlugin(this.aliases);
let plugins = []
plugins.push(
new webpack.optimize.CommonsChunkPlugin({
name: utils.assetsPath('/js/vendor'),
minChunks (module) {
// any required modules inside node_modules are extracted to vendor
return (
module.resource &&
/\.js$/.test(module.resource) &&
module.resource.indexOf(
path.join(__dirname, '../vue/node_modules')
) === 0
)
}
})
)
plugins.push(
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
})
)
if (mix.inProduction()) {
plugins.push(
new webpack.DefinePlugin({
'process.env': env
})
)
plugins.push(
// This instance extracts shared chunks from code splitted chunks and bundles them
// in a separate chunk, similar to the vendor chunk
// see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
new webpack.optimize.CommonsChunkPlugin({
name: 'app.chunkFilename',
async: 'vendor-async',
children: true,
minChunks: 3
})
)
plugins.push(
// Strips out the unnecessary locales from moment
// TODO - do we really need moment?
new webpack.ContextReplacementPlugin(/moment[\\\/]locale$/, /^\.\/(en)$/)
)
// plugins.push(
// new purgeCss({
// paths: glob.sync([
// path.join(__dirname, '../vue/src/components/**/*.vue')
// ]),
// extractors: [
// {
// extractor: class {
// static extract(content) {
// return content.match(/[A-z0-9-:\/]+/g)
// }
// },
// extensions: ['html', 'js', 'php', 'vue']
// }
// ]
// })
// )
}
plugins.push(
// new ExtractTextPlugin("css/devise.css")
)
plugins.push(
// Builds Laravel Mix compatible manifest file
new WebpackLaravelMixManifest()
)
return plugins
}
/**
* Override the generated webpack configuration.
*
* @param {Object} webpackConfig
* @return {void}
*/
webpackConfig(webpackConfig) {
// Example:
// webpackConfig.resolve.extensions.push('.ts', '.tsx');
// delete mix's vue loader and replace it with mine for custom tailwind config
// let vueLoader = webpackConfig.module.rules.filter(rule => {
// return rule.loader === 'vue-loader'
// })
// Trying (and failing) WITH the scss included in Devise.vue
// Results were that it built out the devise.css correctly but ALSO appended it to the
// app.css from the application.
// webpackConfig.module.rules.splice(webpackConfig.module.rules.indexOf(vueLoader), 1,
// {
// test: /\.vue$/,
// loader: 'vue-loader',
// exclude: /bower_components/,
// options: {
// extractCSS: true,
// config: {
// path: '../vue/src/tailwind/tailwind.js'
// }
// }
// }
// )
// Trying (and failing) without the scss included in Devise.vue
// webpackConfig.module.rules.push(
// {
// test: /devise\.scss$/,
// loader: 'postcss-loader',
// exclude: /bower_components/,
// options: {
// extractCSS: true,
// config: {
// path: '../vue/src/tailwind/tailwind.js'
// }
// }
// }
// )
}
/**
* Babel config to be merged with Mix's defaults.
*
* @return {Object}
*/
babelConfig() {
// Example:
// return { presets: ['react'] };
}
}
mix.extend('deviseMix', new DeviseMix());