-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.mix.js
180 lines (147 loc) · 4.68 KB
/
webpack.mix.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
const mix = require( 'laravel-mix' );
const fs = require( 'fs-extra' );
/*
* Sets the development path to assets. By default, this is the `/resources`
* folder in the theme.
*/
const devPath = 'assets';
mix.setPublicPath( 'dist' );
const sassPath = `${devPath}/sass/`;
const grandchildPath = '../../plugins/virtuoso-grandchild/';
const browsersyncConf = `${grandchildPath}browsersync.json`;
const grandchildSassPath = `${grandchildPath}public/assets/src/sass/`;
const config = {
sassPath,
grandchildSassPath
};
/*
* Remove assets/sass/style.scss and dynamically load imported files
* This is useful for when you want to add custom styles in a plugin
*
*/
fs.removeSync( `${sassPath}style.scss` );
fs.writeFile( `${sassPath}style.scss`, buildImports() );
fs.appendFile( `${sassPath}style.scss`, '// DO NOT MODIFY. This file is being generated dynamically through the webpack.mix.js file in the theme root directory' );
/**
* Build up the contents of the sass import file.
*
* @return {string}
*/
function buildImports() {
let imports = [];
imports.push( '../../node_modules/sass-rem/rem' );
imports.push( '../../node_modules/slick-carousel/slick/slick' );
imports.push( 'utilities/index' );
if ( fs.pathExistsSync( `${grandchildSassPath}utilities/index.scss` ) ) {
imports.push( config.grandchildSassPath + 'utilities/index' );
}
imports.push( 'base/index' );
imports.push( 'layouts/index' );
imports.push( 'components/index' );
imports.push( 'templates/index' );
imports.push( 'plugins/index' );
if ( fs.pathExistsSync( `${grandchildSassPath}style.scss` ) ) {
imports.push( config.grandchildSassPath + 'style' );
}
let toImport = '';
imports.forEach( function( sassPath ) {
toImport += '@import \'' + sassPath + '\';\n';
});
return toImport;
}
/*
* Set Laravel Mix options.
*
* @link https://laravel.com/docs/5.6/mix#postcss
* @link https://laravel.com/docs/5.6/mix#url-processing
*/
mix.options({
postCss: [
require( 'postcss-preset-env' ) ({
autoprefixer: { grid: true }
}) ],
processCssUrls: false
});
/*
* Builds sources maps for assets.
*
* @link https://laravel.com/docs/5.6/mix#css-source-maps
*/
mix.sourceMaps();
/*
* Versioning and cache busting. Append a unique hash for production assets. If
* you only want versioned assets in production, do a conditional check for
* `mix.inProduction()`.
*
* @link https://laravel.com/docs/5.6/mix#versioning-and-cache-busting
*/
mix.version();
/*
* Compile JavaScript.
*
* @link https://laravel.com/docs/5.6/mix#working-with-scripts
*/
mix.js( `${devPath}/js/app.js`, 'js' );
// .extract([
// 'slick-carousel'
// ]);
/*
* Compile CSS. Mix supports Sass, Less, Stylus, and plain CSS, and has functions
* for each of them.
*
* @link https://laravel.com/docs/5.6/mix#working-with-stylesheets
* @link https://laravel.com/docs/5.6/mix#sass
* @link https://github.com/sass/node-sass#options
*/
// Sass configuration.
let sassConfig = {
outputStyle: 'expanded',
indentType: 'tab',
indentWidth: 1
};
mix.sass( `${devPath}/sass/style.scss`, 'styles', sassConfig );
/*
* Add custom Webpack configuration.
*
* Laravel Mix doesn't currently minimize images while using its `.copy()`
* function, so we're using the `CopyWebpackPlugin` for processing and copying
* images into the distribution folder.
*
* @link https://laravel.com/docs/5.6/mix#custom-webpack-configuration
* @link https://webpack.js.org/configuration/
*/
mix.webpackConfig({
stats: 'minimal',
devtool: mix.inProduction() ? false : 'source-map',
performance: { hints: false },
externals: { jquery: 'jQuery' }
});
if ( process.env.sync ) {
/*
* Check to see if there is a browsersync configuration file in the virtuoso grandchild plugin
*
*/
if ( fs.pathExistsSync( browsersyncConf ) ) {
let conf = JSON.parse( fs.readFileSync( browsersyncConf, 'utf8' ) );
/*
* Monitor files for changes and inject your changes into the browser.
*
* @link https://laravel.com/docs/5.6/mix#browsersync-reloading
*/
mix.browserSync({
proxy: 'https://' + conf[0].url,
https: {
key: conf[0].key,
cert: conf[0].cert
},
files: [
'dist/**/*',
'Lib/**/*',
'functions.php',
'page-templates/**/*'
] });
} else {
console.log( '\x1b[31m%s\x1b[0m', 'ERROR: No configuration file found for browser sync in the virtuoso-grandchild plugin. If you want to use browsersync with this project then please add a browsersync.conf file to the root directory of the virtuoso-grandchild plugin. The browsersync.conf file should only contain the url of the site you are working on (example.test)' );
process.exit( 1 );
}
}