forked from TRPGEngine/Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnowpack.config.js
142 lines (135 loc) · 3.72 KB
/
snowpack.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const tsconfig = require('./tsconfig.json');
const _ = require('lodash');
const path = require('path');
const pathMap = tsconfig.compilerOptions.paths;
const tspathMountMapping = _.mapValues(pathMap, (val, key) => {
const target = val[0];
const mountedPath = path.relative('./src', target);
return mountedPath.replace(`${path.sep}*`, '').replace(`${path.sep}`, '/');
});
const tsAlias = _(tspathMountMapping)
.mapValues((value) => `./src/${value}`)
.mapKeys((value, key) => key.replace(/\/\*$/, ''))
.value();
// const scriptsPathsMapping = _.fromPairs(
// _.toPairs(tspathMountMapping)
// .map(([key, val]) => {
// if (/^[a-zA-Z]/.test(val)) {
// return [
// `mount:tspath:${key}`,
// `mount ${key.replace(`/*`, '')} --to /_dist_/${val}`,
// ];
// }
// })
// .filter(_.isArray)
// );
// ant design 相关
// Copy from Client/build/config/webpack.base.config.js
const modifyVars = _.toPairs({
'primary-color': '#8C6244',
'error-color': '#e44a4c',
'text-selection-bg': '#1890ff',
})
.map(([key, value]) => `--modify-var="${key}=${value}"`)
.join(' ');
const antdLessCompile = `${path.resolve(
__dirname,
'./node_modules/.bin/lessc'
)} ${path.resolve(
__dirname,
'./node_modules/antd/dist/antd.less'
)} ${path.resolve(
__dirname,
'./public/.snowpack/antd.css'
)} --js ${modifyVars}`;
const antdDarkLessCompile = `${path.resolve(
__dirname,
'./node_modules/.bin/lessc'
)} ${path.resolve(
__dirname,
'./node_modules/antd/dist/antd.dark.less'
)} ${path.resolve(
__dirname,
'./public/.snowpack/antd.dark.css'
)} --js ${modifyVars}`;
module.exports = {
exclude: [
'**/node_modules/**/*',
'**/__tests__/*',
'**/*.@(spec|test).@(js|mjs)',
'**/src/app/**/*',
'**/src/appv2/**/*',
'**/src/portal/**/*',
'**/src/playground/**/*',
],
mount: {
public: '/',
src: '/_dist_',
},
scripts: {
'mount:font': 'mount src/web/assets/fonts --to /fonts',
'mount:favicon': 'mount src/web/assets/img --to /',
},
alias: {
...tsAlias,
'@src': './src/',
},
plugins: [
['@snowpack/plugin-run-script', { name: 'antd compile', cmd: antdLessCompile }],
['@snowpack/plugin-run-script', { name: 'antd dark mode compile', cmd: antdDarkLessCompile }],
'@snowpack/plugin-typescript',
'@snowpack/plugin-sass',
'snowpack-plugin-less',
// '@snowpack/plugin-react-refresh',
[
'snowpack-plugin-replace',
{
list: [
{
from: /process\.env/g,
to: 'import.meta.env',
},
{
from: `require("../../package.json").version`,
to: '"0.0.0"',
},
{
from: `const resBundle = require("i18next-resource-store-loader!./langs/index.js");`,
to: 'import resBundle from "./langs/zh-CN/translation.json"',
},
{
from: `export const resources = resBundle;`,
to: 'export const resources = {"zh-CN": {translation: resBundle}};',
},
{
from: 'import Config from "config";',
to: `const Config = ${JSON.stringify({
sentry: require('config').get('sentry'),
})};`,
},
{
from: 'import "antd/dist/antd.dark.less";',
to: 'import "/.snowpack/antd.dark.css"',
},
{
file: require.resolve('./src/web/assets/css/iconfont.css'),
from: /\.\.\/fonts\/iconfont/g,
to: '/fonts/iconfont',
},
],
},
],
],
installOptions: {
rollup: {
context: 'window',
},
},
devOptions: {
open: 'none',
port: 8089,
out: '.snowpack',
output: 'stream',
hmrErrorOverlay: false,
},
};