-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
100 lines (94 loc) · 2.27 KB
/
webpack.config.babel.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
import path from 'path';
import webpack from 'webpack';
import config from './config.json';
import pckg from './package.json';
const { dependencies } = pckg;
const vendor = Object.keys(dependencies || {});
const debug = process.env.NODE_ENV !== 'production';
const { npm_package_config_port: port } = process.env;
const entryPath = path.resolve('./src', 'modules');
const files = () => {
const names = {};
config.modules.forEach((module) => {
names[module] = path.join(entryPath, module, 'index.jsx');
});
return names;
};
const entryPoints = Object.assign(
{
vendor,
},
files(),
);
const plugins = [
new webpack.optimize.CommonsChunkPlugin({
name: 'commons',
filename: 'commons.js',
minChunks: 2,
chunks: Object.keys(entryPoints).filter(key => key !== 'vendor'),
}),
new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.js' }),
];
export default {
context: __dirname,
devtool: debug ? 'inline-sourcemap' : false,
entry: entryPoints,
output: {
path: path.resolve(debug ? 'dist' : 'public', 'assets/js'),
publicPath: '/assets/js/',
filename: '[name].js',
},
watchOptions: {
poll: true,
},
devServer: {
contentBase: path.resolve(__dirname, 'public'),
compress: true,
port,
},
plugins: debug ? plugins : [
...plugins,
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
PRODUCTION: !debug,
}),
new webpack.optimize.UglifyJsPlugin(),
],
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
rules: [{
test: /\.jsx$/,
include: [
path.resolve(__dirname, 'src', 'modules'),
],
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react'],
},
},
{
test: /\.sass$/,
use: [
'style-loader',
'css-loader',
'sass-loader',
{
loader: 'sass-resources-loader',
options: {
resources: [
'./src/styles/_settings.sass',
'./src/styles/helpers/_bem.sass',
'./src/styles/helpers/_flexbox.sass',
'./src/styles/helpers/_mediaqueries.sass',
],
},
},
],
}],
},
};