-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.mix.js
124 lines (117 loc) · 3.31 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
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' );
/*
* -----------------------------------------------------------------------------
* Theme Export Process
* -----------------------------------------------------------------------------
* Configure the export process in `webpack.mix.export.js`. This bit of code
* should remain at the top of the file here so that it bails early when the
* `export` command is run.
* -----------------------------------------------------------------------------
*/
if ( process.env.export ) {
require( './resources/assets/build/webpack.mix.export.js' );
return;
}
/*
|--------------------------------------------------------------------------
| 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/assets/build/config' );
const assetsDir = config.paths.assets;
const outputDir = config.paths.output;
const options = {
processCssUrls: false,
purifyCss: false,
};
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,
// },
// },
// )
.autoload( {
jquery: [ '$', 'window.jQuery' ],
} )
.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',
// svg4everybody: true,
// svgo: {
// plugins: [
// {
// removeAttrs: { attrs: '(stroke|fill)' },
// },
// {
// removeDimensions: true,
// },
// ],
// },
// },
// },
// ),
],
externals: {
jquery: 'jQuery',
},
} );
if ( mix.inProduction() ) {
mix.versionHash();
}