-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
107 lines (97 loc) · 2.35 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
var webpack = require('webpack')
var path = require('path')
var CopyWebpackPlugin = require('copy-webpack-plugin')
var packageWidgets = require('./package.json').widgets
var __DEV = (process.env.DEV === 'true')
var __DEMO = (process.env.DEMO === 'true')
var __KARMA = (process.env.KARMA === 'true')
var entry = {}
var plugins = []
var devtool = 'source-map'
var loaders = [
{
test: /\.js$/,
loader: 'babel-loader',
include: [
path.resolve(__dirname, 'demo'),
path.resolve(__dirname, 'src'),
],
},
{ test: /\.css$/, loader: 'style?singleton!raw' },
{ test: /\.json$/, loader: 'json-loader' },
]
if (__DEV || __DEMO) {
entry.demo = './demo/demo.js'
} else {
entry.build = './src/ed.js'
}
if (__KARMA) {
entry = './test/index.js'
devtool = 'inline-source-map'
loaders[0].include.push(path.resolve(__dirname, 'test'))
}
if (__DEV && !__KARMA) {
devtool = 'cheap-module-eval-source-map'
entry.test = './test/index.js'
loaders.push({
test: /\.js$/,
loader: 'mocha-loader!babel-loader',
include: [
path.resolve(__dirname, 'test'),
],
})
}
// Build for publish
if (!__DEV && !__KARMA) {
// Needed for React min http://facebook.github.io/react/downloads.html#npm
plugins.push(
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': '"production"',
},
})
)
plugins.push(new webpack.optimize.UglifyJsPlugin())
var copyPatterns = []
if (__DEMO) {
copyPatterns.push({
from: 'index.html',
to: 'index.html',
})
} else {
copyPatterns.push({
from: 'targets/web.html',
to: 'index.html',
})
}
// Copy iframe widgets to dist, whitelisted files and directories only
Object.keys(packageWidgets).forEach(function (key) {
var widget = packageWidgets[key]
widget.include.forEach(function (include) {
copyPatterns.push({
from: 'node_modules/' + key + include,
to: 'node_modules/' + key + include,
})
})
})
plugins.push(new CopyWebpackPlugin(copyPatterns))
}
module.exports = {
entry: entry,
plugins: plugins,
output: {
path: './dist/',
publicPath: '/webpack/',
filename: '[name].js',
sourceMapFilename: '[name].map',
library: 'TheGridEd',
},
debug: __DEV,
devtool: devtool,
module: {
loaders: loaders,
},
resolve: {
extensions: ['', '.js', '.json', '.css'],
},
}