-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
111 lines (89 loc) · 3.01 KB
/
gulpfile.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 gulp = require('gulp');
const elixir = require('laravel-elixir');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const webpackConfig = require('./webpack.config');
const webpackDevConfig = require('./webpack.dev.config');
const mergeWebpack = require('webpack-merge');
const env = require('gulp-env');
const stringifyObject = require('stringify-object');
const file = require('gulp-file');
const argv = require('yargs').argv;//pegar argumentos
const HOST = "localhost"; // constante alterar host de forma global
/*
require('laravel-elixir-vue');
require('laravel-elixir-webpack-official');
Elixir.webpack.config.module.loaders = [];
Elixir.webpack.mergeConfig(webpackConfig);
Elixir.webpack.mergeConfig(webpackDevConfig);
*/
/*
|--------------------------------------------------------------------------
| Elixir Asset Management
|--------------------------------------------------------------------------
|
| Elixir provides a clean, fluent API for defining some basic Gulp tasks
| for your Laravel application. By default, we are compiling the Sass
| file for your application as well as publishing vendor resources.
|
*/
gulp.task('spa-config', () => {
if(argv._.includes('watch')){
env({
file: '.env',
type: 'ini'
});
}
let spaConfig = require('./spa.config');
let string = stringifyObject(spaConfig);
return file('config.js', `module.exports = ${string};`, {src: true})
.pipe(gulp.dest('./resources/assets/spa/js'))
})
gulp.task('webpack-dev-server', () => {
let config = mergeWebpack(webpackConfig, webpackDevConfig);
let inlineHot = [
'webpack/hot/dev-server',
`webpack-dev-server/client?http://${HOST}:8080`
];
for(let key of Object.keys(config.entry)){
config.entry[key] = [config.entry[key]].concat(inlineHot);
}
// config.entry.admin = [config.entry.admin].concat(inlineHot);
// config.entry.spa = [config.entry.spa].concat(inlineHot);
new WebpackDevServer(webpack(config), {
hot: true,
proxy: {
'*': `http://${HOST}:8000`
},
watchOptions: {
poll: true,
aggregateTimeout: 300
},
publicPath: config.output.publicPath,
notInfo: true, // não vai mostra os success
stats: { colors: true}
}).listen(8080, HOST, () => {
console.log("Bundling project...");
})
});
elixir((mix) => {
mix.sass('./resources/assets/admin/sass/admin.scss')
.sass('./resources/assets/spa/sass/spa.scss')
.sass('./resources/assets/site/sass/site.scss')
.copy('./node_modules/materialize-css/fonts/roboto','./public/fonts/roboto');
//.webpack('app.js');
//ficar onhado os aquivos blade e publica
if(argv._.includes('watch')){
gulp.start('spa-config','webpack-dev-server');
mix.browserSync({
host: HOST,
proxy: `http://${HOST}:8080`
});
}else{
//deploy
gulp.start('spa-config');
webpack(require('./webpack.config'),()=>{
console.log("Bundling project..");
});
}
});