forked from Juniper/contrail-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.examples.config.babel.js
98 lines (90 loc) · 2.35 KB
/
webpack.examples.config.babel.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
/*
* Copyright (c) Juniper Networks, Inc. All rights reserved.
*/
import {join} from 'path'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
import UglifyJSPlugin from 'uglifyjs-webpack-plugin'
const fileName = 'contrail-charts-examples'
function absolute (...args) {
return join(__dirname, ...args)
}
const defaultEnv = {dev: true}
export default (env = defaultEnv) => {
const plugins = [
new ExtractTextPlugin('css/' + fileName + '.css'),
]
const loaders = [{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
}),
}, {
test: /\.html/,
loader: 'handlebars-loader',
}, {
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000',
}]
if (env.prod) {
plugins.push(new UglifyJSPlugin({
compress: {
warnings: false
},
mangle: {
keep_fnames: true,
},
sourceMap: true,
include: /\.js$/,
}))
}
loaders.push({
loader: 'babel-loader',
test: /\.js$/,
exclude: /(node_modules)/,
query: {
presets: ['es2015']
}
})
let d3Libs = ['d3', 'd3-selection', 'd3-scale', 'd3-shape', 'd3-array', 'd3-axis', 'd3-ease', 'd3-brush',
'd3-time-format', 'd3-hierarchy', 'd3-geo', 'd3-zoom', 'd3-format']
const externals = {
'jquery': {amd: 'jquery', root: 'jQuery'},
// 'lodash': {amd: 'lodash', root: '_'},
'backbone': {amd: 'backbone', root: 'Backbone'},
'contrail-charts': 'cc',
}
d3Libs.forEach(d3Lib => {
externals[d3Lib] = 'd3'
})
return {
entry: {
'loader': absolute('examples/common/js/loader')
},
devtool: 'source-map',
output: {
path: absolute('/build/examples'),
filename: '[name].bundle.js'
},
module: {loaders},
externals: externals,
resolve: {
modules: [absolute(), 'node_modules'],
alias: {
'fixture': 'tests/generator.js',
'formatter': 'examples/common/js/value-formatters.js',
'constants': 'examples/common/js/constants.js',
'commons': 'examples/common/js/commons.js',
'data-generator': 'examples/common/js/data-generator.js'
},
extensions: ['.js']
},
plugins: plugins,
stats: { children: false },
devServer: {
publicPath: '/build/examples/',
compress: true,
port: 9000,
}
}
}