-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.mix.js
85 lines (76 loc) · 2.52 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
// 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.js('resources/js/app.js', 'public/js')
// .sass('resources/sass/app.scss', 'public/css');
const mix = require('laravel-mix')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
require('dotenv').config();
function resolve(dir) {
return path.join(
__dirname,
'/resources/js/front',
dir
);
}
//加载svg
//https://github.com/JeffreyWay/laravel-mix/issues/1423#issuecomment-360731352
Mix.listen('configReady', webpackConfig => {
// Add "svg" to image loader test
const imageLoaderConfig = webpackConfig.module.rules.find(
rule =>
String(rule.test) ===
String(/\.(woff2?|ttf|eot|svg|otf)$/)
);
imageLoaderConfig.exclude = resolve('icons');
});
mix.webpackConfig({
plugins: [
new HtmlWebpackPlugin({
template: 'resources/js/front/index.html',
filename: 'index.html',
inject: true
}),
new SpriteLoaderPlugin()
],
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'@': __dirname + '/resources/js/front'
},
},
module: {
rules: [
{
test: /\.svg$/,
loader: 'svg-sprite-loader',
include: [resolve('icons')],
options: {
symbolId: 'icon-[name]'
}
},
]
}
});
mix.config.webpackConfig.output = {
chunkFilename: 'js/[name].bundle.js',
publicPath: '/build/front/'
};
mix.version()
mix.js('resources/js/front/bootstrap.js', 'js/bootstrap.js')
.js('resources/js/front/app.js', 'js/front.js')
.sass('resources/js/front/styles/app.scss', 'css/app.css') // 打包后台css
.sass('resources/js/front/styles/index.scss', 'css/front.css') // 打包后台css
.extract(['vue', 'vue-router', 'axios','mint-ui',]) // 提取依赖库
.setResourceRoot('/build/front/') // 设置资源目录
.setPublicPath('./public/build/front') // 设置 mix-manifest.json 目录