-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
95 lines (87 loc) · 2.31 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
const path = require('path');
const webpack = require('webpack')
// Constant with our paths
const paths = {
DIST: path.resolve(__dirname, 'dist'),
JS: path.resolve(__dirname, 'frontend/js'),
};
const platformRoot = '/reqext/mc/v/0.1';
// Webpack configuration
const configuration = {
output: {
path: paths.DIST,
filename: '[name].bundle.js',
library: 'MattcoinModule',
libraryTarget: 'umd',
publicPath: '/'
},
externals: [
(context, req, callback) => {
if (req.startsWith('platform!')) {
return callback(null, `commonjs ${req}`);
}
callback();
}
],
mode: 'development',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
//cacheDirectory: true,
plugins: [/*'babel-plugin-styled-components',*/ 'react-hot-loader/babel']
}
}]
},
{
test: /\.less$/,
use: [{
loader: 'style-loader' // creates style nodes from JS strings
}, {
loader: 'css-loader' // translates CSS into CommonJS
}, {
loader: 'less-loader' // compiles Less to CSS
}]
}
],
},
resolve: {
extensions: ['.js', '.jsx'],
}
};
const development = {
entry: {
main: ['webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000', path.join(paths.JS, 'main.js')] ,
platformModule: [('webpack-hot-middleware/client?path=' + platformRoot + '/__webpack_hmr&name=platformModule&timeout=20000'), path.join(paths.JS, 'platform-module.js')]
},
mode: 'development',
devtool: 'eval-source-map',
plugins: [
new webpack.HotModuleReplacementPlugin(), // uncomment hot lines in frontend/js/App.js
new webpack.NoEmitOnErrorsPlugin()
]
};
const production = {
entry: {
main: path.join(paths.JS, 'main.js') ,
platformModule: path.join(paths.JS, 'platform-module.js')
},
mode: 'production',
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
'process.env': { 'NODE_ENV': JSON.stringify('production') }
}),
],
};
module.exports = (env={dev: true}) => Object.assign(
{},
configuration,
env.prod ? production : development
);