-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.config.doc.babel.js
104 lines (101 loc) · 2.53 KB
/
webpack.config.doc.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
101
102
103
104
import path from "path";
import { argv } from "yargs";
import webpack from "webpack";
import Fiber from "fibers";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
const env = argv.env;
const isDevelopment = env === "development";
const isProduction = env === "production";
if (!(isDevelopment || isProduction)) throw Error(`Invalid Mode: ${env}`);
const libPath = path.resolve(__dirname, "./lib");
const config = {
mode: env,
devtool: isDevelopment ? "source-map" : "",
devServer: {
hot: true,
noInfo: true,
compress: true,
historyApiFallback: true,
https: isProduction,
contentBase: path.resolve(__dirname, "js.org")
},
entry: {
index: [path.resolve(__dirname, "./docs/index.jsx")]
},
output: {
publicPath: isDevelopment ? "/" : "./",
path: path.resolve(__dirname, "./js.org"),
filename: `[name].js`,
chunkFilename: `${isDevelopment ? "[id]" : "[chunkhash]"}.js`
},
module: {
rules: [
{
test: /\.(jsx|js)$/,
exclude: /node_modules/,
use: ["babel-loader"],
enforce: "pre"
},
{
test: /\.(c|sa|sc)ss$/,
exclude: /node_modules/,
use: [
isDevelopment
? { loader: "style-loader" }
: { loader: MiniCssExtractPlugin.loader },
{ loader: "css-loader", options: { sourceMap: isDevelopment } },
{
loader: "sass-loader",
options: {
implementation: require("sass"),
fiber: Fiber
}
}
]
},
{
test: /\.(eot|svg|ttf|woff|woff2|otf)$/,
use: {
loader: "file-loader",
options: {
name: "[path][name].[ext]"
}
}
}
]
},
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: "styles",
test: /\.(c|sc|sa)ss$/,
chunks: "all",
enforce: true
}
}
},
minimize: isProduction
},
resolve: {
extensions: [".js", ".jsx", ".json"]
},
plugins: [
new webpack.ProvidePlugin({
RCLOADABLE: [path.resolve(libPath, "reactLazyLoader"), "default"]
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "docs/index.html"),
chunksSortMode: "none"
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
})
]
};
if (isDevelopment) {
config.entry.index.unshift("webpack/hot/only-dev-server");
}
export default config;