forked from jones2000/HQChart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
113 lines (107 loc) · 2.57 KB
/
webpack.config.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
const path = require('path')
const resolve = require('path').resolve
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const url = require('url')
const glob = require('glob')
const pageEntry=glob.sync('./src/pages/*').reduce((prev,curr)=>{
prev[curr.slice(12)] = curr;
return prev;
},{})
const pageHtmlWebpackPlugin=glob.sync('./src/pages/*').map(item=>{
var pageName=item.slice(12)
return new HtmlWebpackPlugin({
filename: pageName+'.html',
template: 'src/index.html',
chunks:[pageName,'vendor'],
title:pageName
})
})
// console.log(JSON.stringify(pageEntry))
// console.log(JSON.stringify(pageHtmlWebpackPlugin))
const publicPath = ''
module.exports = (options = {}) => ({
entry:Object.assign( {
vendor: './src/vendor',
},pageEntry),
output: {
path: resolve(__dirname, 'dist'),
filename: options.dev ? '[name].js' : '[name].js?[chunkhash]',
chunkFilename: '[id].js?[chunkhash]',
// publicPath: options.dev ? '/assets/' : publicPath
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
'scss': 'style-loader!css-loader!sass-loader'
}
}
},
{
test: /\.less$/,
loader: "style-loader!css-loader!less-loader",
},
{
test: /\.styl/,
use: ['style-loader','css-loader','stylus-loader']
},
{
test: /\.js$/,
use: ['babel-loader'],
exclude: /node_modules/
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader']
},
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
},
{
test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
use: [{
loader: 'url-loader',
options: {
limit: 10000
}
}]
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor']
}),
new webpack.ProvidePlugin({
jQuery: "jquery",
$: "jquery"
})
].concat(pageHtmlWebpackPlugin),
resolve: {
alias: {
'~': resolve(__dirname, 'src')
}
},
devServer: {
host: '127.0.0.1',
port: 8010,
proxy: {
'/api/': {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
},
historyApiFallback: {
index: url.parse(options.dev ? '/assets/' : publicPath).pathname
}
},
devtool: options.dev ? '#eval-source-map' : '#source-map'
})