-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.docs.js
102 lines (99 loc) · 2.26 KB
/
webpack.config.docs.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
const path = require('path');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const webpack = require('webpack');
function entry(env) {
let entries = [];
if (env.dev) {
entries = [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server'
];
}
entries.push('./docs/index');
return entries;
}
function getPlugins(env) {
let plugins = [
new CaseSensitivePathsPlugin()
];
if (env.dev) {
plugins = [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
__TEST__: false
})
];
}
if (env.docs) {
plugins = [
new webpack.DefinePlugin({
__TEST__: false,
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
];
}
return plugins;
}
module.exports = function config(env = {}) {
return {
devServer: {
historyApiFallback: true,
disableHostCheck: true,
host: '0.0.0.0',
hot: true,
publicPath: '/material-react-components'
},
devtool: env.docs ? 'cheap-module-source-map' : 'eval-source-map',
entry: entry(env),
output: {
path: path.resolve(__dirname, env.docs ? '.' : './dist'),
publicPath: '/',
filename: '[name].js'
},
mode: 'development',
module: {
rules: [
{
test: /\.css$/,
exclude: /node_modules/,
use: [
'style-loader',
'css-loader?modules&localIdentName=[name].[local]',
'postcss-loader'
]
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.svg$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
browsers: ['last 2 versions']
}
}
]
]
}
},
'react-svg-loader'
]
}
]
},
plugins: getPlugins(env)
};
};