-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwebpack.config.js
More file actions
123 lines (111 loc) · 3.49 KB
/
webpack.config.js
File metadata and controls
123 lines (111 loc) · 3.49 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
'use strict';
const Webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const USE_CONFIG = process.env.USE_CONFIG || 'local';
const IS_BUILD = process.env.BUILD === 'true';
const IS_TEST = process.env.TEST === 'true';
const CONFIG = {
// devtool: 'source-map',
context: __dirname + '/src',
entry: './index.js',
output: {
path: __dirname + (IS_BUILD ? '/dist/assets' : '/src'),
filename: 'bundle.js',
publicPath: IS_BUILD ? '/assets/' : '/',
},
resolve: {
extensions: ['.json', '.jsx', '.js']
},
plugins: [
new Webpack.DefinePlugin({
'process.env': {
PRODUCTION: (USE_CONFIG === 'production'),
DEVELOPMENT: !IS_BUILD,
USE_CONFIG: JSON.stringify(USE_CONFIG),
IS_TEST: IS_TEST
}
}),
new ExtractTextPlugin('bundle.css'),
new Webpack.ProvidePlugin({
moment: 'moment',
$: 'jquery',
jQuery: 'jquery',
ZeroClipboard: 'zeroclipboard'
}),
new HtmlWebpackPlugin({
template: './index.ejs',
filename: IS_BUILD ? '../index.html' : 'index.html',
IS_BUILD: IS_BUILD,
E2E_TEST: false
}),
new Webpack.LoaderOptionsPlugin({
options: {
postcss: [autoprefixer],
'html-minify-loader': {
empty: true,
cdata: true,
comments: false,
dom: {
lowerCaseAttributeNames: false,
}
},
}
}),
],
module: {
rules: [{
test: /\.js$/,
exclude: /(node_modules|vendor|\*.spec.js)/,
loaders: ['ng-annotate-loader', 'babel-loader'],
}, {
test: /\.html$/,
loaders: ['raw-loader', 'html-minify-loader']
}, {
test: /\.less$/,
loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader!postcss-loader!less-loader' })
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })
}, {
test: /\.((woff2?|svg)(\?v=[0-9]\.[0-9]\.[0-9]))|(woff2?|svg|jpe?g|png|gif|ico)$/,
loaders: ['url-loader'],
exclude: /(img)/,
}, {
test: /\.((ttf|otf|eot)(\?v=[0-9]\.[0-9]\.[0-9]))|(ttf|otf|eot)$/,
loaders: ['file-loader']
}, {
include: /\.json$/,
loaders: ['json-loader']
}]
},
devServer: {
port: 8080,
host: 'localhost',
historyApiFallback: true,
watchOptions: {
aggregateTimeout: 300,
poll: 1000
}
}
};
switch (IS_BUILD) {
case true:
CONFIG.plugins.push(
new Webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: true,
comments: false
})
);
break;
case false:
if (!IS_TEST) {
const Dashboard = require('webpack-dashboard');
const DashboardPlugin = require('webpack-dashboard/plugin');
CONFIG.plugins.push(new DashboardPlugin(Dashboard.setData));
}
break;
}
module.exports = CONFIG;