-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.docs.config.js
119 lines (114 loc) · 3.99 KB
/
webpack.docs.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"use strict";
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const webpack = require("webpack");
function readVersionFromPackageJson(packageJsonPath) {
const content = require(packageJsonPath);
return "v" + content.version;
}
let libraryVersion = process.env.TRAVIS_TAG;
if (!libraryVersion) {
libraryVersion = readVersionFromPackageJson(path.resolve("package.json"));
}
function createConfig(publicPath, output) {
return {
entry: {
index: [require.resolve("babel-polyfill"), "./docs/index.tsx"],
},
output: {
path: output,
publicPath: publicPath,
filename: "[name].js",
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
loader: "ts-loader",
},
{
test: /\.md$/,
exclude: /node_modules/,
use: ["react-hot-loader", "babel-loader", "./loaders/markdown-loader"],
},
{
test: /\.(css|less)$/,
exclude: /node_modules/,
use: [
"classnames-loader",
"style-loader",
{
loader: "css-loader",
options: {
modules: true,
localIdentName: "[name]-[local]-[hash:base64:4]",
},
},
"less-loader",
],
},
{
test: /\.(woff|woff2|eot|svg|ttf|gif|png)$/,
exclude: /node_modules/,
use: "file-loader",
},
{
test: /\.(js|jsx)$/,
include: /retail-ui/,
exclude: /retail-ui(\\|\/)node_modules/,
use: "babel-loader",
},
{
test: /\.(css|less)$/,
include: /retail-ui/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
localIdentName: "[name]-[local]-[hash:base64:4]",
},
},
"less-loader",
],
},
{
test: /\.(woff|woff2|eot|svg|ttf|gif|png)$/,
include: /retail-ui/,
use: "file-loader",
},
],
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
modules: ["node_modules", "web_modules"],
alias: {
Demo: path.resolve(__dirname, "./docs/components/Demo.tsx"),
src: path.resolve(__dirname, "src"),
docs: path.resolve(__dirname, "docs"),
},
},
plugins: [
new HtmlWebpackPlugin({
template: "./docs/index.html",
}),
new webpack.DefinePlugin({
"process.env.libraryVersion": JSON.stringify(libraryVersion),
"process.env.libraryVersionEscaped": JSON.stringify(libraryVersion.replace("-", "--")),
REACT_UI_PACKAGE: JSON.stringify("retail-ui"),
}),
],
};
}
if (process.env.NODE_ENV === "production") {
module.exports = [
createConfig(
"http://tech.skbkontur.ru/react-ui-validations/" + libraryVersion + "/",
path.join(__dirname, "dist/" + libraryVersion)
),
createConfig("http://tech.skbkontur.ru/react-ui-validations/", path.join(__dirname, "dist")),
];
} else {
module.exports = createConfig("/", path.join(__dirname, "dist"));
}