-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathwebpack.docs.config.js
107 lines (102 loc) · 2.88 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
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;
}
const libraryVersion = readVersionFromPackageJson(path.resolve('package.json'));
const isProd = process.env.NODE_ENV === 'production';
function createConfig(publicPath, output) {
return {
entry: ['core-js/stable', './docs/index.tsx'],
output: {
path: output,
publicPath,
filename: '[name].js',
},
mode: isProd ? 'production' : 'development',
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
{
loader: 'string-replace-loader',
options: {
search: /__REACT_UI_PACKAGE__/g,
replace: '@skbkontur/react-ui',
},
},
],
},
{
test: /\.md$/,
exclude: /node_modules/,
use: ['babel-loader', './loaders/markdown-loader'],
},
{
test: /\.(woff|woff2|eot|svg|ttf|gif|png)$/,
use: 'file-loader',
},
{
test: /\.(css|less)$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
mode: 'global',
localIdentName: '[name]-[local]-[hash:base64:4]',
},
},
},
'less-loader',
],
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
Demo: path.resolve(__dirname, './docs/Common/Demo.tsx'),
SourceCode: path.resolve(__dirname, './docs/Common/SourceCode.tsx'),
src: path.resolve(__dirname, './src'),
docs: path.resolve(__dirname, './docs'),
'react-dom': '@hot-loader/react-dom',
},
},
plugins: [
new HtmlWebpackPlugin({
template: './docs/index.html',
}),
new webpack.DefinePlugin({
'process.env.libraryVersion': JSON.stringify(libraryVersion),
'process.env.libraryVersionEscaped': JSON.stringify(libraryVersion.replace('-', '--')),
}),
],
devServer: {
historyApiFallback: true,
host: '0.0.0.0',
},
};
}
if (isProd) {
module.exports = [
createConfig(
'//tech.skbkontur.ru/react-ui-validations/' + libraryVersion + '/',
path.join(__dirname, 'dist/' + libraryVersion),
),
createConfig('//tech.skbkontur.ru/react-ui-validations/', path.join(__dirname, 'dist')),
];
} else {
module.exports = createConfig('/', path.join(__dirname, 'dist'));
}