forked from aalphaa/wookteam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.mix.js
114 lines (107 loc) · 4.46 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
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| 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 the application as well as bundling up all the JS files.
|
*/
//复制资源
mix.copy('resources/assets/statics/public', 'public');
//生成vue页面js
mix.js('resources/assets/js/main/app.js', 'js/app.js');
//生成css样式文件
mix.sass('resources/assets/sass/app.scss', 'css');
//配置webpack
mix.webpackConfig({
output: {
// 路由懒加载文件路径
chunkFilename: 'js/build/[name].js?[hash:8]',
},
devServer: {
disableHostCheck: true,
},
module: {
rules: [{
// 图片资源保存路径规则
test: /(\.(png|jpe?g|gif)$|^((?!font).)*\.svg$)/,
loaders: [
{
loader: 'file-loader',
options: {
name: path => {
path = path.replace(/\\/g, '/');
// 自定义部分
try {
if (/\/resources\/assets\//.test(path)) {
let file = path.substring(path.indexOf('/resources/assets/') + '/resources/assets/'.length);
if (file) {
if (file.substring(0, 3) === 'js/') file = 'pages/' + file.substring(3);
if (file.substring(0, 7) === 'images/') file = file.substring(7);
return 'images/' + file + '?[hash:8]'
}
}
} catch (e) { }
// 系统定义部分
if (!/node_modules|bower_components/.test(path)) {
return (
Config.fileLoaderDirs.images + '/[name].[ext]?[hash:8]'
);
}
return (
Config.fileLoaderDirs.images + '/vendor/' + path.replace(
/((.*(node_modules|bower_components))|images|image|img|assets)\//g,
''
) + '?[hash:8]'
);
},
publicPath: Config.resourceRoot
}
}, {
loader: 'img-loader',
options: Config.imgLoaderOptions
}
]
}, {
// 字体资源保存路径规则
test: /(\.(woff2?|ttf|eot|otf)$|font.*\.svg$)/,
loader: 'file-loader',
options: {
name: path => {
path = path.replace(/\\/g, '/');
// 自定义部分
try {
if (/\/resources\/assets\//.test(path)) {
let file = path.substring(path.indexOf('/resources/assets/') + '/resources/assets/'.length);
if (file) {
if (file.substring(0, 3) === 'js/') file = 'pages/' + file.substring(3);
if (file.substring(0, 7) === 'fonts/') file = file.substring(7);
return 'fonts/' + file + '?[hash:8]'
}
}
} catch (e) { }
// 系统定义部分
if (!/node_modules|bower_components/.test(path)) {
return Config.fileLoaderDirs.fonts + '/[name].[ext]?[hash:8]';
}
return (
Config.fileLoaderDirs.fonts + '/vendor/' + path.replace(
/((.*(node_modules|bower_components))|fonts|font|assets)\//g,
''
) + '?[hash:8]'
);
},
publicPath: Config.resourceRoot
}
}]
}
}).options({
uglify: {
uglifyOptions: {
compress: { inline: false }
}
}
});