forked from baklazaner/botpress-messenger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.js
107 lines (100 loc) · 2.41 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
const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')
const pkg = require('./package.json')
const path = require('path')
const nodeConfig = {
devtool: 'source-map',
entry: ['./src/index.js'],
output: {
path: path.resolve(__dirname, './bin'),
filename: 'node.bundle.js',
libraryTarget: 'commonjs2',
publicPath: __dirname
},
externals: [nodeExternals(), 'botpress'],
target: 'node',
node: {
__dirname: false
},
resolve: {
extensions: ['.js']
},
module: {
rules: [{
test: /\.js$/,
use: {
loader: 'babel-loader',
query: {
presets: ['latest', 'stage-0'],
plugins: ['transform-object-rest-spread']
}
},
exclude: /node_modules/,
}]
}
}
const webConfig = {
devtool: 'source-map',
entry: ['./src/views/index.jsx'],
output: {
path: path.resolve(__dirname, './bin'),
publicPath: '/js/modules/',
filename: 'web.bundle.js',
libraryTarget: 'assign',
library: ['botpress', pkg.name]
},
externals: {
'react': 'React',
'react-dom': 'ReactDOM'
},
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [{
test: /\.jsx?$/,
use: {
loader: 'babel-loader',
query: {
presets: ['latest', 'stage-0', 'react'],
plugins: ['transform-object-rest-spread', 'transform-decorators-legacy']
}
},
exclude: /node_modules/,
}, {
test: /\.scss$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
query: {
modules: true,
importLoaders: 1,
localIdentName: pkg.name + '__[name]__[local]___[hash:base64:5]',
}
},
{ loader: 'sass-loader' }
]
}, {
test: /\.css$/,
use: [ { loader: 'style-loader' }, { loader: 'css-loader' }]
}, {
test: /\.woff|\.woff2|\.svg|.eot|\.ttf/,
use: { loader: 'file-loader', query: { name: '../fonts/[name].[ext]' } }
}]
}
}
const compiler = webpack([nodeConfig, webConfig])
const postProcess = function(err, stats) {
if (err) throw err
console.log(stats.toString('minimal'))
}
if (process.argv.indexOf('--compile') !== -1) {
compiler.run(postProcess)
} else if (process.argv.indexOf('--watch') !== -1) {
compiler.watch(null, postProcess)
}
module.exports = {
web: webConfig,
node: nodeConfig
}