Skip to content

Commit 8c39dd9

Browse files
committedOct 27, 2020
chore: 调整snowpack, 使其node_module引入的less文件支持编译参数
1 parent 0ee2e16 commit 8c39dd9

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed
 

‎package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
"@prettier/plugin-xml": "^0.10.0",
166166
"@sentry/webpack-plugin": "^1.13.0",
167167
"@snowpack/plugin-react-refresh": "^2.3.2",
168+
"@snowpack/plugin-run-script": "^2.1.7",
168169
"@snowpack/plugin-sass": "^1.0.1",
169170
"@snowpack/plugin-typescript": "^1.0.1",
170171
"@types/classnames": "^2.2.10",

‎public/index.html

+1-11
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,13 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta name="description" content="Web site created using create-snowpack-app" />
88
<title>Snowpack App</title>
9+
<link rel="stylesheet" type="text/css" href="/.snowpack/antd.css" />
910
</head>
1011
<body>
1112
<div id="root">
1213
<div id="app"></div>
1314
</div>
1415
<noscript>You need to enable JavaScript to run this app.</noscript>
15-
<script type="module">import "antd/dist/antd.css";</script>
1616
<script type="module" src="/_dist_/web/index.js"></script>
17-
<!--
18-
This HTML file is a template.
19-
If you open it directly in the browser, you will see an empty page.
20-
21-
You can add webfonts, meta tags, or analytics to this file.
22-
The build step will place the bundled scripts into the <body> tag.
23-
24-
To begin the development, run `npm start` or `yarn start`.
25-
To create a production bundle, use `npm run build` or `yarn build`.
26-
-->
2717
</body>
2818
</html>

‎snowpack.config.js

+35-9
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,37 @@ const tsAlias = _(tspathMountMapping)
2828
// .filter(_.isArray)
2929
// );
3030

31+
// ant design 相关
32+
// Copy from Client/build/config/webpack.base.config.js
33+
const modifyVars = _.toPairs({
34+
'primary-color': '#8C6244',
35+
'error-color': '#e44a4c',
36+
'text-selection-bg': '#1890ff',
37+
})
38+
.map(([key, value]) => `--modify-var="${key}=${value}"`)
39+
.join(' ');
40+
const antdLessCompile = `${path.resolve(
41+
__dirname,
42+
'./node_modules/.bin/lessc'
43+
)} ${path.resolve(
44+
__dirname,
45+
'./node_modules/antd/dist/antd.less'
46+
)} ${path.resolve(
47+
__dirname,
48+
'./public/.snowpack/antd.css'
49+
)} --js ${modifyVars}`;
50+
const antdDarkLessCompile = `${path.resolve(
51+
__dirname,
52+
'./node_modules/.bin/lessc'
53+
)} ${path.resolve(
54+
__dirname,
55+
'./node_modules/antd/dist/antd.dark.less'
56+
)} ${path.resolve(
57+
__dirname,
58+
'./public/.snowpack/antd.dark.css'
59+
)} --js ${modifyVars}`;
60+
3161
module.exports = {
32-
// extends: '@snowpack/app-scripts-react',
33-
install: [
34-
'antd/dist/antd.dark.css'
35-
],
3662
exclude: [
3763
'**/node_modules/**/*',
3864
'**/__tests__/*',
@@ -55,6 +81,8 @@ module.exports = {
5581
'@src': './src/',
5682
},
5783
plugins: [
84+
['@snowpack/plugin-run-script', { name: 'antd compile', cmd: antdLessCompile }],
85+
['@snowpack/plugin-run-script', { name: 'antd dark mode compile', cmd: antdDarkLessCompile }],
5886
'@snowpack/plugin-typescript',
5987
'@snowpack/plugin-sass',
6088
'snowpack-plugin-less',
@@ -86,17 +114,15 @@ module.exports = {
86114
})};`,
87115
},
88116

89-
// 这里是临时解决方案
90-
// https://github.com/snowpackjs/snowpack/discussions/1360
91117
{
92118
from: 'import "antd/dist/antd.dark.less";',
93-
to: 'import "antd/dist/antd.dark.css";',
119+
to: 'import "/.snowpack/antd.dark.css"',
94120
},
95121
{
96122
file: require.resolve('./src/web/assets/css/iconfont.css'),
97123
from: /\.\.\/fonts\/iconfont/g,
98124
to: '/fonts/iconfont',
99-
}
125+
},
100126
],
101127
},
102128
],
@@ -111,6 +137,6 @@ module.exports = {
111137
port: 8089,
112138
out: '.snowpack',
113139
output: 'stream',
114-
hmrErrorOverlay: false
140+
hmrErrorOverlay: false,
115141
},
116142
};

0 commit comments

Comments
 (0)