-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.js
More file actions
111 lines (102 loc) · 2.8 KB
/
webpack.config.js
File metadata and controls
111 lines (102 loc) · 2.8 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
const glob = require('glob');
const path = require('path');
const merge = require('webpack-merge');
const webpack = require('webpack');
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
app: path.join(__dirname, 'assets/javascripts/application.js'),
widgets: glob.sync('./widgets/**/*.js'),
build: path.join(__dirname, 'public/assets'),
gridster: path.join(__dirname, 'node_modules/gridster/dist'),
d3: path.join(__dirname, 'node_modules/d3/d3.min.js'),
rickshaw: path.join(__dirname, 'node_modules/rickshaw/rickshaw.js')
};
process.env.BABEL_ENV = TARGET;
const common = {
entry: {
application: PATHS.app,
widgets: PATHS.widgets
},
resolve: {
extensions: ['', '.js', '.jsx', 'css', 'scss'],
modulesDirectories: ['node_modules', PATHS.gridster],
alias: {
d3: PATHS.d3
}
},
output: {
path: PATHS.build,
publicPath: '/assets/',
filename: '[name].js'
},
module: {
loaders: [
{ test: /\.css$/, loaders: ['style', 'css'] },
{ test: /\.scss$/, loaders: ['style', 'css', 'sass'] },
{ test: /\.jsx?$/, loaders: ['babel?cacheDirectory'] },
{
test: /\.(svg|png|jpe?g|gif)(\?\S*)?$/,
loader: 'url?limit=1000&name=images/[name].[ext]'
},
{
test: /\.(eot|woff|woff2|ttf)(\?\S*)?$/,
loader: 'url?limit=1000&name=fonts/[name].[ext]'
},
{
test: require.resolve('jquery-knob'),
loader: "imports?require=>false,define=>false,this=>window"
},
{
test: PATHS.d3,
loader: "script"
},
{
test: require.resolve('rickshaw'),
loader: "script"
}
]
}
};
// Development Environment
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devtool: 'eval-source-map',
devServer: {
contentBase: PATHS.build,
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
// display only errors to reduce the amount of output
stats: 'errors-only',
// Binding address of webpack-dev-server
// Read more: https://github.com/kittoframework/kitto/wiki/Customize-Asset-Watcher
host: process.env.KITTO_ASSETS_HOST,
port: process.env.KITTO_ASSETS_PORT
},
plugins: [new webpack.HotModuleReplacementPlugin()]
});
}
// Production Environment
if (TARGET === 'build') {
var CompressionPlugin = require("compression-webpack-plugin");
module.exports = merge(common, {
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
keep_fnames: true
},
mangle: {
keep_fnames: true
}
}),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.html$/,
verbose: true
})
]
});
}