generated from niiknow/vue-wp-plugin-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.mix.js
143 lines (126 loc) · 3.35 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
const fs = require('fs')
const path = require('path')
const mix = require('laravel-mix')
const webpack = require('webpack')
const StylelintPlugin = require('stylelint-webpack-plugin')
require('laravel-mix-tailwind')
const webpackConfig = {
externals: {
'jquery': 'jQuery',
'vue': 'Vue'
},
plugins: [
/**
* Stylelint
*
* @link https://github.com/webpack-contrib/stylelint-webpack-plugin
*/
new StylelintPlugin({
context: './assets',
files: '**/*.css',
fix: true,
}),
],
resolve: {
extensions: ['.js', '.json', '.vue', '.sass', '.scss', '.ts'],
alias: {
'~src': path.resolve(__dirname, 'src'),
'vue$': 'vue/dist/vue.esm.js'
}
},
stats: {
children: true
},
devServer: {
port: 31337 // in case your port 8080 and 31337 are taken, replace this
}
}
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/
mix.setPublicPath('public/')
mix.ts('src/admin/admin.ts', 'js')
.vue({
version: 3,
extractStyles: true
})
mix.ts('src/frontend/frontend.ts', 'js')
.vue({
version: 3,
extractStyles: true
})
mix.ts('src/frontview/frontview.ts', 'js')
.vue({
version: 3,
extractStyles: true
})
// bare minimum packages: ['core-js', 'vue-router', '@vue/devtools-api']
mix.extract() // empty to extract all
const postcssPlugins = [
require('autoprefixer'),
require('postcss-import'),
require('postcss-preset-env')({ stage: 1 }),
require('postcss-pxtorem')({
propList: ['*'],
selectorBlackList: ['border'],
mediaQuery: true,
})
]
mix.options({
postCss: postcssPlugins
})
.postCss(
'assets/admin.css',
'css'
)
.postCss(
'assets/frontend.css',
'css'
)
.postCss(
'assets/frontview.css',
'css'
)
mix.tailwind().version()
if (mix.inProduction()) {
mix.sourceMaps()
}
mix.after(() => {
let manifest = JSON.parse(
fs.readFileSync('./public/mix-manifest.json').toString()
)
let adminHtml = fs.readFileSync('./assets/admin.html').toString()
let frontendHtml = fs.readFileSync('./assets/frontend.html').toString()
let frontviewHtml = fs.readFileSync('./assets/frontview.html').toString()
for (let path of Object.keys(manifest)) {
adminHtml = adminHtml.replace(path.replace(/^\//, ''), manifest[path].replace(/^\//, ''))
frontendHtml = frontendHtml.replace(path.replace(/^\//, ''), manifest[path].replace(/^\//, ''))
frontviewHtml = frontviewHtml.replace(path.replace(/^\//, ''), manifest[path].replace(/^\//, ''))
}
fs.writeFileSync('./public/admin.html', adminHtml)
fs.writeFileSync('./public/frontend.html', frontendHtml)
fs.writeFileSync('./public/frontview.html', frontviewHtml)
})
mix.webpackConfig(webpackConfig)
.browserSync({
serveStatic: ['./'],
serveStaticOptions: {
extensions: ['html'] // don't need to provide html extension, this create pretty urls
}
})
mix.override((config) => {
config.watchOptions = {
ignored: [
'**/node_modules/**',
'**/public/**',
'**/vendor/**'
]
}
})