-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.mix.js
172 lines (154 loc) · 4.23 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
const mix = require('laravel-mix')
const path = require('path')
const fse = require('fs-extra')
require('laravel-mix-polyfill')
require('laravel-mix-purgecss')
const SVGSpritemapPlugin = require('svg-spritemap-webpack-plugin')
const StylelintPlugin = require('stylelint-webpack-plugin')
const ESLintPlugin = require('eslint-webpack-plugin')
const purgecssWordpress = require('purgecss-with-wordpress')
// Use these functions when resolving paths
const src = relPath => path.resolve(__dirname, process.env.MIX_SRC_DIR, relPath)
const dist = relPath => path.resolve(__dirname, process.env.MIX_DIST_DIR, relPath)
const frameworkDir = process.env.FRAMEWORK_ROOT ? relPath => path.resolve(__dirname, process.env.FRAMEWORK_ROOT, relPath) : src
const purgeCssRoot = process.env.PURGECSS_ROOT || 'resources'
/*
|--------------------------------------------------------------------------
| Config
|--------------------------------------------------------------------------
*/
mix
// Basic config
.setPublicPath(process.env.MIX_PUBLIC_PATH)
.setResourceRoot(process.env.MIX_RESOURCE_ROOT)
// Module aliases
.webpackConfig({
resolve: {
alias: {
_utils: frameworkDir('js/utils'),
_glsl: frameworkDir('glsl'),
_components: frameworkDir('js/components'),
_store: frameworkDir('js/store.js'),
'../../../build/three.module.js': '../../../src/Three'
}
}
})
// Set up SASS entry point
.sass(src('scss/style.scss'), dist('css'))
// Set up the JS entry point
.js(src('js/theme.js'), dist('scripts'))
// ensure mix is using the browserslist entry from the package.json
.polyfill({
enabled: true,
useBuiltIns: "usage",
targets: false,
debug: process.env.BROWSERSLIST_DEBUG === 'true'
})
// PurgeCSS
.purgeCss({
defaultExtractor: (content) => content.match(/[a-zA-Z0-9-@./_]+/g) || [],
content: [
`${purgeCssRoot}/**/*.html`,
`${purgeCssRoot}/**/*.js`,
`${purgeCssRoot}/**/*.jsx`,
`${purgeCssRoot}/**/*.ts`,
`${purgeCssRoot}/**/*.tsx`,
`${purgeCssRoot}/**/*.php`,
`${purgeCssRoot}/**/*.vue`,
`${purgeCssRoot}/**/*.twig`,
`${purgeCssRoot}/**/*.njk`
],
safelist: {
standard: [
...purgecssWordpress.safelist,
// eslint-disable-next-line no-eval
...eval(process.env.PURGECSS_WHITELIST) || []
],
// eslint-disable-next-line no-eval
deep: eval(process.env.PURGECSS_WHITELIST_DEEP) || []
}
})
// Set up Browser Sync
.browserSync({
proxy: process.env.MIX_BS_PROXY,
open: false,
files: [
process.env.MIX_DIST_DIR + 'css/*.css',
process.env.MIX_DIST_DIR + 'scripts/*.js',
purgeCssRoot + '/**/*.blade.php',
purgeCssRoot + '/**/*.html'
],
snippetOptions: {
ignorePaths: 'wp-admin/**'
}
})
// Webpack plugins
.webpackConfig(() => {
const plugins = [
new SVGSpritemapPlugin(src('svg-sprite/*.svg'), {
output: {
filename: 'images/svgsprite.svg',
chunk: { keep: true },
svgo: {
plugins: [
{ addClassesToSVGElement: { className: 'svg-sprite' } },
{ removeTitle: true }
]
}
},
sprite: { prefix: false }
})
]
if (!mix.inProduction()) {
plugins.push(
new ESLintPlugin({
emitWarning: true,
failOnError: false
})
)
plugins.push(
new StylelintPlugin({
context: process.cwd(),
files: process.env.MIX_SRC_DIR + "scss/**/*.s?(a|c)ss",
emitWarning: true
})
)
}
return { plugins }
})
// Additional loaders
.webpackConfig({
module: {
rules: [
{
test: /\.(glsl|frag|vert|vs|fs)$/,
exclude: /node_modules/,
use: [
'raw-loader',
'glslify-loader'
]
}
]
}
})
// Copy any images from resources to public.
.copyDirectory(src('images'), dist('images'))
.copyDirectory(src('models'), dist('models'))
// Append version strings in mix-manifest.
.version()
// ensure the dist images folder is empty and fresh
fse.emptyDir(dist('images'))
fse.emptyDir(dist('models'))
/*
|--------------------------------------------------------------------------
| ENV handling
|--------------------------------------------------------------------------
*/
if (!mix.inProduction()) {
// Include separate source maps in development builds.
mix
.webpackConfig({ devtool: 'cheap-module-source-map' })
.sourceMaps()
} else {
// only run in production
}