-
Notifications
You must be signed in to change notification settings - Fork 16
/
snowpack.config.js
142 lines (136 loc) · 3.5 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/mini-program/**/*',
'**/src/portal/**/*',
'**/src/playground/**/*',
'**/src/plugins/**/*',
],
mount: {
public: '/',
dist: '/',
src: '/_dist_',
},
routes: [
{ match: 'routes', src: '.*', dest: '/index.html' },
{ src: '/favicon.ico', dest: '/_dist_/web/assets/img/favicon.ico' },
],
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: 'import Config from "config";',
to: `const Config = ${JSON.stringify(
require('./build/config/configObj')
)};`,
},
{
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: '/_dist_/web/assets/fonts/iconfont',
},
],
},
],
],
packageOptions: {
rollup: {
context: 'window',
},
},
devOptions: {
open: 'none',
port: 8089,
out: '.snowpack',
output: 'stream',
hmrErrorOverlay: false,
},
};