-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.babel.js
108 lines (107 loc) · 3.59 KB
/
webpack.config.babel.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
let webpack = require('webpack');
let path = require("path");
let serverHost = getIPAdress();
let HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
index: path.resolve(__dirname, './index.js'),
},
output: {
path: path.join(__dirname, 'dist'), //文件的产出路径
publicPath: '/dist/', //文件的引用路径,内存路径,开启服务,做热加载的时候,实际上引用的就是内存路径,即使删除了本地文件,也不会有任何影响,改变的实际上是内存上的文件。
filename: "js/bundle.js"
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
scss: 'vue-style-loader!css-loader!sass-loader', // <style lang="scss">
sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax' // <style lang="sass">
}
}
},
// {
// test: /\.html$/,
// loader: "raw-loader"
// },
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
presets: ["es2015", "stage-0"],
plugins: ['syntax-dynamic-import']
}
},
// {
// test: /\.html$/,
// loader: 'html-loader',
// options: {
// // 除了img的src,还可以继续配置处理更多html引入的资源
// attrs: ['img:src']
// }
// },
{
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader'
},
{
test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
loader: 'url-loader',
options: {
limit: 8192,
name: 'images/[name].[ext]'
},
//loader: 'url-loader?limit=8192&name=images/[hash:8].[name].[ext]'
},
{
test: /\.html$/,
loader: 'html-loader'
},
]
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, 'dist/html/index.html'), //生成的html存放路径,相对于path
template: path.resolve(__dirname, './index.html'), //ejs模板路径,前面最好加上loader用于处理
inject: 'body', //js插入的位置,true/'head'/'body'/false
}),
],
devServer: {
contentBase: './',
host: serverHost,
port: 9095, //默认9090
inline: true, //可以监控js变化
hot: true//热启动
},
resolve: {
alias: {
vue: 'vue/dist/vue.js'
},
extensions: ['.js', '.scss', '.vue', '.json']
}
};
/**
* @description 获取本地IP地址
* @returns {string|*}
*/
function getIPAdress() {
let interfaces = require('os').networkInterfaces();
for (let devName in interfaces) {
let iface = interfaces[devName];
for (let i = 0; i < iface.length; i++) {
let alias = iface[i];
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
return alias.address;
}
}
}
}