-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
162 lines (138 loc) · 3.67 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
/*eslint-disable */
'use strict'
var path = require('path');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var NODE_ENV = process.env.NODE_ENV || 'development';
var ENV = process.env.npm_lifecycle_event;
var isTest = ENV === 'test' || ENV === 'karma' || NODE_ENV === 'test';
var isProd = ENV === 'build' || NODE_ENV === 'production';
const PATHS = {
src: path.join(__dirname, 'src'),
dist: path.join(__dirname, 'dist'),
}
function webpackConfig() {
var config = {}
config.entry = isTest ? {} : {
build: [
//'babel-polyfill',
path.join(PATHS.src, 'app/app'),
],
vendor: [
'angular',
'angular-ui-router'
],
}
config.output = isTest ? {}: {
path: PATHS.dist,
publicPath: isProd ? '/' : 'http://localhost:8081/',
filename: isProd ? '[name]-[hash:7].js' : '[name].build.js',
chunkFilename: isProd ? '[name]-[hash:7].js' : '[name].build.js',
}
if (isTest) {
config.devtool = 'inline-source-map'
} else if (isProd) {
config.devtool = 'source-map'
} else {
config.devtool = 'eval'
}
config.module = {
preLoaders: [],
postLoaders: [],
loaders: [{
test: /\.js$/,
include: PATHS.src,
loader: 'babel',
exclude: '/node_modules/',
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract(
'style',
'css?sourceMap!postcss'
),
}, {
test: /\.json$/,
loader: 'json-loader',
}, {
test: /\.(eot|ttf|woff|woff2|wav|mp3)$/,
loader: 'url?name=[path][name]-[hash:7].[ext]',
}, {
test: /\.(png|ico|jpe?g|gif|svg)$/i,
loaders: [
'file?name=[path][name]-[hash:7].[ext]&limit=8192',
],
}, {
test: /\.html$/,
loader: 'html',
},],
};
config.postcss = [
autoprefixer({
browsers: ['>1%', 'last 2 versions'],
}),
];
config.plugins = [
// Sort module indices by occurrence frequency
new webpack.optimize.OccurenceOrderPlugin(),
new ExtractTextPlugin('styles.css', { allChunks: true }),
];
if (isProd) {
config.plugins.push(
new webpack.NoErrorsPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
unsafe: true,
},
sourceMap: false
})
)
}
if (!isTest) {
config.plugins.push(
new HtmlWebpackPlugin({
template: 'src/index.html',
inject: 'body',
minify: {
removeAttributeQuotes: true
},
favicon: 'src/favicon.ico'
}),
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor-[hash:7].js')
)
}
config.resolve = {
extensions: ['', '.js'],
modulesDirectories: ['node_modules'],
alias: {
'src': path.resolve(__dirname, './src'),
'app': path.resolve(__dirname, './src/app'),
'assets': path.resolve(__dirname, './src/assets'),
'styles': path.resolve(__dirname, './src/assets/styles'),
'images': path.resolve(__dirname, './src/assets/images'),
'components': path.resolve(__dirname, './src/app/components')
}
}
config.resolveLoader = {
extensions: ['', '.js'],
modulesDirectories: ['node_modules'],
moduleTemplates: ['*-loader', '*'],
root: path.join(__dirname, 'node_modules')
}
config.devServer = {
contentBase: PATHS.src,
historyApiFallback: true,
inline: true,
progress: true,
port: 8081,
hot: true,
stats: {
colors: true
}
}
return config
}
module.exports = webpackConfig()