forked from JhumanJ/OpnForm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.mix.js
72 lines (64 loc) · 1.83 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
const path = require('path')
const fs = require('fs-extra')
const mix = require('laravel-mix')
require('laravel-mix-versionhash')
const tailwindcss = require('tailwindcss')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
mix
.js('resources/js/app.js', 'public/dist/js').vue()
.sass('resources/sass/app.scss', 'public/dist/css')
.options({
processCssUrls: false,
postCss: [tailwindcss('./tailwind.config.js')]
})
.disableNotifications()
.extract(['vue', 'vue-router', 'vuex', 'axios', 'vue-meta',
'vue-i18n', 'portal-vue'])
if (mix.inProduction()) {
mix
// .extract() // Disabled until resolved: https://github.com/JeffreyWay/laravel-mix/issues/1889
// .version() // Use `laravel-mix-versionhash` for the generating correct Laravel Mix manifest file.
.versionHash()
// Vapor config
const ASSET_URL = process.env.ASSET_URL + '/'
mix.webpackConfig(webpack => {
return {
plugins: [
new webpack.DefinePlugin({
'process.env.ASSET_PATH': JSON.stringify(ASSET_URL)
})
],
output: {
publicPath: ASSET_URL
}
}
})
} else {
mix.sourceMaps()
}
mix.webpackConfig({
plugins: [
new BundleAnalyzerPlugin()
],
resolve: {
extensions: ['.js', '.json', '.vue'],
alias: {
'~': path.join(__dirname, './resources/js')
}
},
output: {
chunkFilename: 'dist/js/[chunkhash].js',
path: path.resolve(__dirname, mix.inProduction() ? './public/build' : './public')
}
})
mix.then(() => {
if (mix.inProduction()) {
process.nextTick(() => publishAssets())
}
})
function publishAssets () {
const publicDir = path.resolve(__dirname, './public')
fs.removeSync(path.join(publicDir, 'dist'))
fs.copySync(path.join(publicDir, 'build', 'dist'), path.join(publicDir, 'dist'))
fs.removeSync(path.join(publicDir, 'build'))
}