forked from mineral-ui/mineral-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
103 lines (100 loc) · 2.44 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
/* @flow */
const path = require('path');
const webpack = require('webpack');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const CopyWebpackPlugin = require('copy-webpack-plugin');
const NODE_ENV = process.env.NODE_ENV || 'development';
const ANALYZE = process.env.ANALYZE;
const isProduction = NODE_ENV === 'production';
const GOOGLE_TRACKING_ID = isProduction ? 'UA-107538931-1' : null;
const licenseHeader = `/**!
* Mineral UI
* Copyright 2017 CA
* License: Apache-2.0
*/`;
module.exports = {
entry: {
index: './src/website/index.js'
},
output: {
filename: '[name].js',
path: path.resolve('./dist/website'),
publicPath: '/'
},
mode: isProduction ? 'production' : 'development',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.md$/,
loader: 'raw-loader'
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
resolve: {
mainFields: ['browser', 'module', 'main']
},
devServer: {
contentBase: path.join(__dirname, './src/website'),
compress: true,
disableHostCheck: true,
host: '0.0.0.0',
historyApiFallback: {
index: '/'
}
},
devtool: isProduction ? 'source-map' : 'cheap-module-eval-source-map',
optimization: {
runtimeChunk: true,
splitChunks: {
chunks: 'all'
}
},
plugins: (() => {
let plugins = [
new webpack.DefinePlugin({
GOOGLE_TRACKING_ID: JSON.stringify(GOOGLE_TRACKING_ID)
}),
new webpack.BannerPlugin({
banner: licenseHeader,
raw: true,
entryOnly: true
}),
new HtmlWebpackPlugin({
template: './src/website/index.html',
GOOGLE_TRACKING_ID
}),
new CopyWebpackPlugin([
{
context: './src/website/public',
from: '**/*'
}
]),
new CircularDependencyPlugin({
exclude: /node_modules/,
failOnError: false, // TODO: Set to true once resolve all current issues
allowAsyncCycles: false,
cwd: process.cwd()
})
];
if (ANALYZE) {
plugins.push(
new BundleAnalyzerPlugin({
analyzerHost: '0.0.0.0'
})
);
}
return plugins;
})()
};