forked from vmware-archive/pui-styleguide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontend_webpack.config.babel.js
95 lines (90 loc) · 2.51 KB
/
frontend_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
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const {NamedModulesPlugin, HotModuleReplacementPlugin} = require('webpack');
const prod = process.argv.indexOf('-p') !== -1;
const htmlPlugin = new HtmlWebpackPlugin({template: 'index.html'});
const prodConfig = {
mode: 'production',
entry: ['@babel/polyfill', './src/index.js'],
plugins: [
new NamedModulesPlugin(),
new ExtractTextPlugin('app.css'),
new CompressionPlugin(),
htmlPlugin
]
};
const devConfig = {
mode: 'development',
entry: ['@babel/polyfill', 'react-hot-loader/patch', './src/index.js'],
devServer: {
host: '0.0.0.0',
hot: true,
historyApiFallback: true,
publicPath: '/',
clientLogLevel: 'error',
contentBase: path.resolve(__dirname, 'dist'),
stats: {
warningsFilter: /Module not found: Error: Can't resolve .*.css/
}
},
plugins: [
htmlPlugin,
new HotModuleReplacementPlugin()
],
devtool: 'cheap-module-source-map'
};
module.exports = {
...(prod ? prodConfig : devConfig),
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/'
},
resolve: {
alias: {
'node_modules/pivotal-ui': path.resolve(__dirname, '../pivotal-ui/src'),
'pivotal-ui': path.resolve(__dirname, '../pivotal-ui/src')
}
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: require.resolve('babel-loader'),
options: {
// This is necessary to make sure babel-loader knows
// to load the .babelrc both here and in ../pivotal-ui.
// see: https://babeljs.io/docs/en/options#babelrcroots
babelrcRoots: ['.', '../pivotal-ui']
}
},
{
test: /\.(eot|ttf|woff)$/,
use: 'url-loader'
},
{
test: /\.md$/,
use: ['json-loader', './src/helpers/markdown_loader.js']
},
{
test: /\.s?css$/,
use: prod
? ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: ['file-loader', 'image-webpack-loader']
}
]
},
node: {
fs: 'empty' // so that babel doesn't blow up with weird error messages occasionally
}
};