-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.mix.js
107 lines (101 loc) · 2.63 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
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
const SpritesmithPlugin = require( 'webpack-spritesmith' );
const SVGSpritemapPlugin = require( 'svg-spritemap-webpack-plugin' );
const mix = require( 'laravel-mix' );
require( 'laravel-mix-polyfill' );
require( 'laravel-mix-versionhash' );
require( 'laravel-mix-criticalcss' );
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for your application, as well as bundling up your JS files.
|
*/
const config = require( './resources/build/config' );
const assetsDir = config.paths.assets;
const outputDir = config.paths.output;
const options = {
extractVueStyles: false,
processCssUrls: false, // Webpack url() rewriting
purifyCss: false,
postCss: [
require( 'autoprefixer' ),
],
};
mix
.options( options )
.setPublicPath( outputDir )
.sourceMaps( false )
.sass( `${ assetsDir }/scss/main.scss`, `${ outputDir }/css/main.css` )
.criticalCss(
{
enabled: mix.inProduction(),
paths: {
base: config.devUrl,
templates: `./${ outputDir }/css/critical/`,
},
urls: config.criticalCss.urls,
options: {
minify: true,
},
},
)
.js( `${ assetsDir }/js/main.js`, `${ outputDir }/js/main.js` )
.polyfill( {
enabled: true,
useBuiltIns: 'usage',
targets: false,
} )
// .extract()
.copy( `${ assetsDir }/fonts/**/*`, `${ outputDir }/fonts` )
.copy( `${ assetsDir }/img/**/*`, `${ outputDir }/img` )
.copy( `${ assetsDir }/lang/**/*.mo`, `${ outputDir }/lang` )
.copy( `${ assetsDir }/svg/**/*`, `${ outputDir }/svg` )
.copy( `${ assetsDir }/sprites/*`, `${ outputDir }/sprites` )
.browserSync( {
proxy: config.devUrl,
files: config.watch,
} )
.webpackConfig( {
plugins: [
new CleanWebpackPlugin(),
new SpritesmithPlugin( {
src: {
cwd: `${ assetsDir }/sprites/img/`,
glob: '**/*.png',
},
target: {
image: `${ assetsDir }/sprites/map.png`,
css: `${ assetsDir }/scss/common/_sprite.scss`,
},
apiOptions: {
cssImageRef: '../sprites/map.png',
},
} ),
new SVGSpritemapPlugin(
[ `${ assetsDir }/sprites/svg/**/*.svg` ],
{
output: {
filename: 'sprites/map.svg',
svgo: {
plugins: [
{
removeAttrs: { attrs: '(stroke|fill)' },
},
],
},
},
},
),
],
externals: {
jquery: 'jQuery',
},
} );
if ( mix.inProduction() ) {
mix.versionHash();
}