forked from EasyDarwin/EasyDarwin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
169 lines (166 loc) · 5.25 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
function resolve(dir) {
return path.resolve(__dirname, dir)
}
module.exports = {
entry: {
"index": ['babel-polyfill', resolve('index.js')],
"login": ['babel-polyfill', resolve('login.js')]
},
output: {
path: resolve('../www'),
chunkFilename: 'js/[name].[chunkhash:8].js',
filename: 'js/[name].[chunkhash:8].js'
},
externals: {
'jquery': '$'
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.common.js',
'assets': resolve('assets'),
'components': resolve('components')
}
},
devServer: {
host: '0.0.0.0',
useLocalIp: true,
proxy: {
"*": {
target: `http://localhost:10008`,
secure: false
}
}
},
module: {
rules: [{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
}, {
test: /pretty-bytes/,
loader: 'babel-loader'
}, {
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
css: ExtractTextPlugin.extract({
publicPath: '../',
fallback: 'vue-style-loader', //this is a dep of vue-loader, so no need to explicitly install if using npm3
use: 'css-loader'
})
},
postcss: [
require('autoprefixer')()
]
}
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
publicPath: '../',
fallback: "style-loader",
use: "css-loader"
})
}, {
test: /\.less$/,
use: ExtractTextPlugin.extract({
publicPath: '../',
fallback: "style-loader",
use: "css-loader!less-loader"
})
}, {
test: /\.scss$/,
use: ExtractTextPlugin.extract({
publicPath: '../',
fallback: "style-loader",
use: "css-loader!sass-loader"
})
}, {
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
outputPath: "images/",
limit: 10000,
name: "[name].[hash:8].[ext]"
}
}, {
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
outputPath: "fonts/",
limit: 10000,
name: "[name].[hash:8].[ext]"
}
}, {
test: /\.(swf|mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
outputPath: "media/",
limit: 10000,
name: "[name].[hash:8].[ext]"
}
}]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
"window.jQuery": 'jquery',
"window.$": 'jquery'
}),
new webpack.HashedModuleIdsPlugin(),
new CopyWebpackPlugin([
{ from: 'externals' },
{ from: 'node_modules/easy-player/dist/component/easy-player-lib.min.js', to: 'js/'},
{ from: 'node_modules/easy-player/dist/component/easy-player-fluent.swf'},
{ from: 'node_modules/easy-player/dist/component/easy-player.swf'}
]),
new ExtractTextPlugin("css/[name].[chunkhash:8].css"),
new HtmlWebpackPlugin({
filename: 'login.html',
title: 'EasyDarwin 登录',
inject: true,
chunks: ['login'],
template: './template-login.html'
}),
new HtmlWebpackPlugin({
filename: 'index.html',
title: 'EasyDarwin',
inject: true, // head -> Cannot find element: #app
chunks: ['index'],
template: './template.html'
})
]
};
if (process.env.NODE_ENV == "production") {
module.exports.plugins = (module.exports.plugins || []).concat([
new CleanWebpackPlugin(['www'], {
root: resolve("../")
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/g,
cssProcessor: require('cssnano'),
cssProcessorOptions: { discardComments: { removeAll: true } },
canPrint: true
}),
new webpack.optimize.UglifyJsPlugin({
comments: false,
compress: {
warnings: false
}
})
])
}