forked from botpress/botpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.js
198 lines (190 loc) · 5.15 KB
/
webpack.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
var webpack = require('webpack')
var path = require('path')
var CopyWebpackPlugin = require('copy-webpack-plugin')
var nodeExternals = require('webpack-node-externals')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
var ExtensionsPlugin = require('./extensions/extensions-plugin')
var nodeConfig = {
devtool: process.env.NODE_ENV === 'production' ? 'source-map' : 'eval-cheap-module-source-map',
entry: [path.resolve(__dirname, './index.js')],
output: {
path: path.resolve(__dirname, './lib'),
filename: 'node.bundle.js',
libraryTarget: 'commonjs2',
publicPath: __dirname
},
externals: [nodeExternals()],
target: 'node',
node: {
__dirname: false
},
resolve: {
extensions: ['.js'],
alias: {
'~': path.resolve(__dirname, './src'),
'+': path.resolve(__dirname, './extensions/lite')
}
},
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['latest', 'stage-0'],
plugins: ['transform-object-rest-spread']
}
}
],
exclude: /node_modules/
}
]
},
plugins: [
ExtensionsPlugin.beforeResolve,
ExtensionsPlugin.afterResolve,
new webpack.DefinePlugin({
BP_EDITION: JSON.stringify(process.env.BOTPRESS_EDITION || 'lite')
})
]
}
var webConfig = {
bail: true,
devtool: process.env.NODE_ENV === 'production' ? 'source-map' : 'eval-cheap-module-source-map',
entry: {
// vendor: [ // This doesn't work with lite.bundle.js
// 'axios',
// 'bluebird',
// 'howler',
// 'knex',
// 'lodash',
// 'moment',
// 'react',
// 'react-bootstrap',
// 'react-codemirror',
// 'react-dom',
// 'react-jsonschema-form'
// ],
web: './src/web/index.jsx',
lite: './src/web/lite.jsx'
},
output: {
path: path.resolve(__dirname, './lib/web/js'),
publicPath: '/js/',
filename: '[name].bundle.js'
},
resolve: {
extensions: ['.js', '.jsx', '.css'],
alias: {
'~': path.resolve(__dirname, './src/web'),
'+': path.resolve(__dirname, './extensions/lite')
}
},
plugins: [
// new webpack.optimize.CommonsChunkPlugin({
// name: 'vendor',
// minChunks: Infinity
// }),
ExtensionsPlugin.beforeResolve,
ExtensionsPlugin.afterResolve,
new webpack.DefinePlugin({
BP_EDITION: JSON.stringify(process.env.BOTPRESS_EDITION || 'lite'),
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new UglifyJSPlugin({ sourceMap: true, cache: true }),
new webpack.NoEmitOnErrorsPlugin(),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, './src/web/index.html'),
to: path.resolve(__dirname, './lib/web/index.html')
},
{
from: path.resolve(__dirname, './src/web/lite.html'),
to: path.resolve(__dirname, './lib/web/lite/index.html')
},
{
from: path.resolve(__dirname, './src/web/img'),
to: path.resolve(__dirname, './lib/web/img')
},
{
from: path.resolve(__dirname, './src/web/audio'),
to: path.resolve(__dirname, './lib/web/audio')
}
])
],
module: {
rules: [
{
test: /\.jsx?$/i,
exclude: /node_modules/i,
use: {
loader: 'babel-loader',
options: {
presets: ['latest', 'stage-0', 'react'],
plugins: ['transform-object-rest-spread', 'transform-decorators-legacy'],
compact: true,
babelrc: false,
cacheDirectory: true
}
}
},
{
test: /\.scss$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
},
{ loader: 'postcss-loader' },
{ loader: 'sass-loader' }
]
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.woff|\.woff2|\.svg|.eot|\.ttf/,
use: [{ loader: 'file-loader', options: { name: '../fonts/[name].[ext]' } }]
}
]
}
}
var showNodeEnvWarning = function() {
if (process.env.NODE_ENV !== 'production') {
console.log('*****')
console.log('WARNING: You are currently building Botpress in development; NOT generating a production build')
console.log('Run with NODE_ENV=production to create a production build instead')
console.log('*****')
}
}
var compiler = webpack([webConfig, nodeConfig])
var postProcess = function(err, stats) {
if (err) {
throw err
}
console.log(stats.toString('minimal'))
}
if (process.argv.indexOf('--compile') !== -1) {
showNodeEnvWarning()
compiler.run(postProcess)
} else if (process.argv.indexOf('--watch') !== -1) {
compiler.watch(null, postProcess)
}
var runCompiler = function(cb) {
showNodeEnvWarning()
compiler.run(function(err, stats) {
postProcess(err, stats)
cb()
})
}
module.exports = { web: webConfig, node: nodeConfig, run: runCompiler }