-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathwebpack.config.js
More file actions
138 lines (133 loc) · 3.65 KB
/
webpack.config.js
File metadata and controls
138 lines (133 loc) · 3.65 KB
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
/*
* @Author: zhouningyi
* @Date: 2016-10-01 14:18:17
* @Last Modified by: zhouningyi
* @Last Modified time: 2017-01-07 18:33:33
*/
var path = require('path');
var config = require('./config')
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var autoprefixer = require('autoprefixer');
var precss = require('precss');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var OpenBrowserPlugin = require('open-browser-webpack-plugin');
var ip = require('ip');
var src = path.resolve(__dirname, './');
var SFTP_CONFIG = {
on: process.env.SFTP || false, // default false
conf: {
host: 'example.com',
port: '22', // default
username: 'username',
password: 'password',
from: '/path/to/localDistPath',
to: '/path/to/serverPath',
}
};
var vNodeModules = path.join(__dirname, 'node_modules');
module.exports = {
entry: [
'babel-polyfill',
path.join(src, config.path)
],
resolveLoader: {
fallback: [vNodeModules]
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: './min.js',
publicPath: '/'
},
resolve: {
fallback: [vNodeModules],
extensions: ['', '.js', '.jsx'],
alias: {
// ================
// 自定义路径名
// ================
CONTAINERS: path.join(src, 'containers'),
COMPONENTS: path.join(src, 'components'),
ACTIONS: path.join(src, 'actions'),
REDUCERS: path.join(src, 'reducers'),
STORE: path.join(src, 'store'),
CONFIG: path.join(src, 'conf'),
//
ROUTES: path.join(src, 'routes'),
SERVICES: path.join(src, 'services'),
UTILS: path.join(src, 'utils'),
HOC: path.join(src, 'utils/HoC'),
MIXIN: path.join(src, 'utils/mixins'),
VIEWS: path.join(src, 'views'),
},
},
module: {
root: vNodeModules,
loaders: [{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: [
'babel-preset-es2015',
'babel-preset-react',
'babel-preset-stage-0',
'babel-preset-stage-2',
].map(require.resolve),
}
}, {
test: /\.scss$/,
loader: 'style!css!postcss!sass'
}, {
test: /\.less$/,
loader: 'style!css!postcss!less'
}, {
test: /\.css$/,
loader: 'style!css!postcss'
}, {
test: /\.json$/,
loader: 'json'
}, {
test: /\.(png|jpg|gif|svg)$/,
loader: 'url?limit=25000&name=[name].[ext]?[hash]'
}, {
test: /\.(eot|woff|ttf|svg)$/,
loader: 'url?limit=30000&name=[name]-[hash].[ext]'
}],
},
postcss: function() {
return [autoprefixer, precss];
},
plugins: process.env.NODE_ENV === 'production' ? SFTP_CONFIG.on ? [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new ExtractTextPlugin('[name].[contenthash].css'),
] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new ExtractTextPlugin('[name].[contenthash].css'),
] : [
new webpack.optimize.OccurrenceOrderPlugin(),
// new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new ExtractTextPlugin('[name].css'),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'index.html'),
chunkSortMode: 'none'
}),
new OpenBrowserPlugin({
url: `http://${ip.address()}:8080`
})
],
devtool: process.env.NODE_ENV === 'production' ? '' : '#inline-source-map'
};