This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
webpack.config.js
executable file
·104 lines (93 loc) · 2.54 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
const path = require('path');
const webpack = require('webpack');
const config = require('./gulp/config');
const BBErrorNotify = require('./gulp/utils/BBErrorNotify');
const paths = {
entry: `${config.src}/scripts/app.js`,
blocks: `${config.src}/scripts/blocks.js`,
admin: `${config.src}/scripts/admin.js`,
packages: `${config.src}/scripts/packages/index.js`,
out: `${config.dist}/`,
};
const webpackConfig = {
cache: true,
context: path.resolve(__dirname, './src'),
entry: {
bundle: path.join(__dirname, paths.entry),
blocks: path.join(__dirname, paths.blocks),
admin: path.join(__dirname, paths.admin),
packages: path.join(__dirname, paths.packages),
// If using a library/libraries include them in their own vendor bundle. Example below:
// vendor: [ 'jquery' ]
},
output: {
path: path.join(__dirname, paths.out),
filename: '[name].js',
},
externals: {
benenson: {
this: 'benenson',
},
},
module: {
rules: [
// Expose App to window.
{
test: /app\.js$/,
loader: 'expose-loader',
query: 'App',
},
// expose `benenson` to window
{
test: /packages\/index\.js$/,
loader: 'expose-loader',
query: 'benenson',
},
// Run Babel and lint JS
{
test: /\.js$/,
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
options: {
presets: [
['env', { modules: false }],
['react'],
['stage-0'],
],
plugins: ['babel-plugin-lodash'].map(require.resolve),
},
},
{
loader: 'eslint-loader',
options: {
configFile: '.eslintrc',
emitError: false,
emitWarning: true,
},
},
],
},
],
},
plugins: [
// Global vars for checking dev environment.
new webpack.DefinePlugin({
__DEV__: JSON.stringify(process.env.NODE_ENV !== 'production'),
__PROD__: JSON.stringify(process.env.NODE_ENV === 'production'),
__TEST__: JSON.stringify(process.env.NODE_ENV === 'test'),
}),
],
};
// Production/Dev Specific Config
if (process.env.NODE_ENV === 'production') {
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin());
} else {
webpackConfig.devtool = 'sourcemap';
webpackConfig.plugins.push(
// Notify on errors / warnings. Plugin code below.
new BBErrorNotify()
);
}
module.exports = webpackConfig;