-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.mix.js
141 lines (118 loc) · 4.09 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
let mix = require('laravel-mix');
const path = require('path');
const fs = require('fs-extra');
const webpack = require('webpack');
require('laravel-mix-versionhash');
// // const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
/*
* npm i jquery --save or yarn add jquery
* commentout below code to enable juery autoloading
* this allows you to use $() in all files.
*/
// ===compile our main.js file
mix.js('resources/assets/main.js', path.resolve(__dirname, './public/js'));
// .sass('resources/sass/style.scss', path.resolve(__dirname, './public/css'));
// Add any additional vendor modules that need to be cached
// remove any unused libraries in the array as they will be included in the vendor bundle
// .extract(['vue', 'bootstrap-vue', 'axios']);
mix.autoload({
jquery: ['$', 'window.jQuery', 'jQuery'],
});
// ===public path
mix.setPublicPath('./');
// sourcemaps
if (!mix.inProduction()) {
mix.sourceMaps();
} else {
// mix.versionHash();
mix.version();
}
//====set alias for isotope
mix.webpackConfig({
resolve: {
alias: {
'~': path.resolve(__dirname, 'resources/assets'),
src: path.resolve(__dirname, 'resources/assets/'),
assets: path.resolve(__dirname, 'resources/assets/assets/'),
components: path.resolve(__dirname, 'resources/assets/components/'),
pages: path.resolve(__dirname, 'resources/assets/components/pages/'),
admin: path.resolve(__dirname, 'resources/assets/components/admin/'),
site: path.resolve(__dirname, 'resources/assets/components/site/'),
img: path.resolve(__dirname, 'resources/assets/assets/img/'),
},
},
// https://github.com/JeffreyWay/laravel-mix/issues/936#issuecomment-331418769
output: {
publicPath: '/spa/',
// publicPath: path.resolve(__dirname, 'public'),
chunkFilename: 'public/js/[name].[chunkhash].js',
path: mix.config.hmr ? '/' : path.resolve(__dirname, './'),
},
// plugins: [
// // reduce bundle size by ignoring moment js local files
// new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
// ]
});
// Setup Autoprefixer
mix.options({
postCss: [
require('autoprefixer')(),
// require('postcss-rtl')()
],
});
// set path for production link
// if (mix.inProduction()) {
// mix.setResourceRoot('/public/')
// }
// if (!mix.inProduction()) {
mix.setResourceRoot('/spa/');
// }
// mix.browserSync('timeclock.test');
// Disable all OS notifications
// mix.disableNotifications()
// Disable all Success notifications
// mix.disableSuccessNotifications()
// // mix.setPublicPath();
// mix.setResourceRoot('/time_clock/');
// 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()
// } 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: mix.config.hmr ? '/' : path.resolve(__dirname, './public/build')
// }
// })
mix.then(() => {
// if (!mix.config.hmr) {
process.nextTick(() => publishAseets());
// }
});
function publishAseets() {
const publicDir = path.resolve(__dirname, './public');
console.log('Working');
// if (mix.inProduction()) {
// fs.removeSync(path.join(publicDir, 'js/chunks'));
// }
// fs.removeSync('./public/mix-manifest.json');
fs.copySync('./mix-manifest.json', './public/mix-manifest.json');
fs.removeSync('./mix-manifest.json');
// fs.copySync(path.join(__dirname, 'fonts'), path.join(publicDir, 'fonts'));
// fs.removeSync(path.join(__dirname, 'fonts'));
// fs.copySync(path.join(__dirname, 'images'), path.join(publicDir, 'images'));
// fs.removeSync(path.join(__dirname, 'images'));
}