Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pro-blocks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
pro-blocks
Commits
aedadc36
Commit
aedadc36
authored
Jul 03, 2018
by
陈帅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix theme change
parent
e3a73309
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
162 additions
and
11 deletions
+162
-11
.gitignore
.gitignore
+2
-1
.webpackrc.js
.webpackrc.js
+6
-7
scripts/AddlocalIdentName.js
scripts/AddlocalIdentName.js
+47
-0
scripts/getLocalIdentName.js
scripts/getLocalIdentName.js
+8
-0
scripts/mergeLessPlugin.js
scripts/mergeLessPlugin.js
+73
-0
scripts/replacedefaultLess.js
scripts/replacedefaultLess.js
+11
-0
webpack.config.js
webpack.config.js
+15
-3
No files found.
.gitignore
View file @
aedadc36
...
...
@@ -28,3 +28,4 @@ jsconfig.json
*.log
functions/mock
temp/**
.webpackrc.js
View file @
aedadc36
...
...
@@ -29,19 +29,18 @@ export default {
cssLoaderOptions
:
{
modules
:
true
,
getLocalIdent
:
(
context
,
localIdentName
,
localName
)
=>
{
if
(
context
.
resourcePath
.
includes
(
'
node_modules
'
))
{
if
(
context
.
resourcePath
.
includes
(
'
node_modules
'
)
||
context
.
resourcePath
.
includes
(
'
ant.design.pro.less
'
)
)
{
return
localName
;
}
let
antdProPath
=
context
.
resourcePath
.
match
(
/src
(
.*
)
/
)[
1
].
replace
(
'
.less
'
,
''
);
if
(
context
.
resourcePath
.
includes
(
'
components
'
))
{
antdProPath
=
antdProPath
.
replace
(
'
components/
'
,
''
);
}
const
antdProPath
=
context
.
resourcePath
.
match
(
/src
(
.*
)
/
)[
1
].
replace
(
'
.less
'
,
''
);
const
arr
=
antdProPath
.
split
(
'
/
'
)
.
map
(
a
=>
a
.
replace
(
/
([
A-Z
])
/g
,
'
-$1
'
))
.
map
(
a
=>
a
.
toLowerCase
());
return
`antd-pro
${
arr
.
join
(
'
-
'
)}
-
${
localName
}
`
.
replace
(
'
--
'
,
'
-
'
);
return
`antd-pro
${
arr
.
join
(
'
-
'
)}
-
${
localName
}
`
.
replace
(
/--/g
,
'
-
'
);
},
},
};
scripts/AddlocalIdentName.js
0 → 100644
View file @
aedadc36
/* eslint-disable */
const
postcss
=
require
(
'
postcss
'
);
const
syntax
=
require
(
'
postcss-less
'
);
const
LocalIdentNameplugin
=
postcss
.
plugin
(
'
LocalIdentNameplugin
'
,
({
localIdentName
})
=>
{
return
lessAST
=>
{
// loop add localIdentName
const
loop
=
nodes
=>
{
nodes
.
forEach
(
item
=>
{
// Not converted :global
if
(
item
.
nodes
&&
item
.
selector
!==
'
:global
'
)
{
loop
(
item
.
nodes
);
}
// 将global的 节点加到 parents
if
(
item
.
selector
===
'
:global
'
)
{
const
parentNodes
=
item
.
parent
.
nodes
;
const
childrenNodes
=
item
.
nodes
;
const
index
=
parentNodes
.
findIndex
(
node
=>
{
return
node
.
selector
===
'
:global
'
;
});
childrenNodes
.
unshift
(
index
,
1
);
Array
.
prototype
.
splice
.
apply
(
parentNodes
,
item
.
nodes
);
item
.
parent
.
nodes
=
parentNodes
;
return
;
}
// 删除 :global(className) 保留 className
if
(
item
.
selector
&&
!
item
.
selector
.
includes
(
'
(
'
))
{
if
(
item
.
selector
.
includes
(
'
:global(
'
))
{
// converted :global(.className)
const
className
=
item
.
selector
.
match
(
/:global
\((\S
*
)\)
/
)[
1
];
item
.
selector
=
className
;
return
;
}
const
className
=
item
.
selector
.
replace
(
/
\.
/g
,
`.
${
localIdentName
}
`
);
item
.
selector
=
className
;
}
});
};
loop
(
lessAST
.
nodes
);
};
});
const
AddlocalIdentName
=
(
lessPath
,
lessText
,
localIdentName
)
=>
{
return
postcss
([
LocalIdentNameplugin
({
localIdentName
})]).
process
(
lessText
,
{
syntax
});
};
module
.
exports
=
AddlocalIdentName
;
scripts/getLocalIdentName.js
0 → 100644
View file @
aedadc36
module
.
exports
=
path
=>
{
const
antdProPath
=
path
.
match
(
/src
(
.*
)
/
)[
1
].
replace
(
'
.less
'
,
''
);
const
arr
=
antdProPath
.
split
(
'
/
'
)
.
map
(
a
=>
a
.
replace
(
/
([
A-Z
])
/g
,
'
-$1
'
))
.
map
(
a
=>
a
.
toLowerCase
());
return
`antd-pro
${
arr
.
join
(
'
-
'
)}
-`
.
replace
(
/--/g
,
'
-
'
);
};
scripts/mergeLessPlugin.js
0 → 100755
View file @
aedadc36
#!/usr/bin/env node
/**
* 这个方法用来处理 css-modlue
* 由于没有开源插件,所以自己撸了一个
*/
const
fs
=
require
(
'
fs
'
);
const
path
=
require
(
'
path
'
);
const
getLocalIdentName
=
require
(
'
./getLocalIdentName
'
);
const
AddlocalIdentName
=
require
(
'
./AddlocalIdentName
'
);
const
replacedefaultLess
=
require
(
'
./replacedefaultLess
'
);
// read less file list
const
lessArray
=
[
'
@import "../node_modules/antd/lib/style/themes/default.less";
'
];
const
loopAllLess
=
parents
=>
{
const
paths
=
fs
.
readdirSync
(
parents
);
const
promiseList
=
[];
paths
.
forEach
(
itemPath
=>
{
if
(
itemPath
===
'
style
'
||
itemPath
===
'
demo
'
)
{
return
;
}
// file status
const
fileStatus
=
fs
.
lstatSync
(
path
.
join
(
parents
,
itemPath
));
// is file
// is Directory
if
(
fileStatus
.
isDirectory
())
{
return
loopAllLess
(
path
.
join
(
parents
,
itemPath
));
}
// is less file
if
(
itemPath
.
indexOf
(
'
.less
'
)
>
-
1
)
{
const
relaPath
=
path
.
join
(
parents
,
itemPath
);
// post css add localIdentNameplugin
const
fileContent
=
replacedefaultLess
(
relaPath
);
// push less file
promiseList
.
push
(
AddlocalIdentName
(
relaPath
,
fileContent
,
getLocalIdentName
(
relaPath
)).
then
(
result
=>
{
lessArray
.
push
(
result
);
})
);
}
});
return
Promise
.
all
(
promiseList
);
};
class
mergeLessPlugin
{
constructor
(
options
)
{
const
defaulOptions
=
{
stylesDir
:
path
.
join
(
__dirname
,
'
./src/
'
),
outFile
:
path
.
join
(
__dirname
,
'
./tmp/ant.design.pro.less
'
),
};
this
.
options
=
Object
.
assign
(
defaulOptions
,
options
);
this
.
generated
=
false
;
}
apply
(
compiler
)
{
const
{
options
}
=
this
;
compiler
.
plugin
(
'
emit
'
,
(
compilation
,
callback
)
=>
{
const
{
outFile
}
=
options
;
// covert less
if
(
fs
.
existsSync
(
outFile
))
{
fs
.
unlinkSync
(
outFile
);
}
else
{
fs
.
mkdir
(
path
.
dirname
(
outFile
));
}
loopAllLess
(
options
.
stylesDir
).
then
(()
=>
{
fs
.
writeFileSync
(
outFile
,
lessArray
.
join
(
'
\n
'
));
callback
();
});
});
}
}
module
.
exports
=
mergeLessPlugin
;
scripts/replacedefaultLess.js
0 → 100644
View file @
aedadc36
const
fs
=
require
(
'
fs-extra
'
);
const
replacedefaultLess
=
lessPath
=>
{
const
fileContent
=
fs
.
readFileSync
(
lessPath
).
toString
();
let
lessString
=
fileContent
;
if
(
lessString
.
includes
(
"
@import '~antd/lib/style/themes/default.less'
"
))
{
lessString
=
lessString
.
replace
(
"
@import '~antd/lib/style/themes/default.less';
"
,
''
);
}
return
lessString
.
replace
(
/@import '.*
\/
utils.less';/
,
''
);
};
module
.
exports
=
replacedefaultLess
;
webpack.config.js
View file @
aedadc36
import
AntDesignThemePlugin
from
'
antd-theme-webpack-plugin
'
;
import
MergeLessPlugin
from
'
./scripts/mergeLessPlugin
'
;
const
path
=
require
(
'
path
'
);
export
default
webpackConfig
=>
{
// 将所有 less 合并为一个供 themePlugin使用
const
outFile
=
path
.
join
(
__dirname
,
'
./temp/ant-design-pro.less
'
);
const
stylesDir
=
path
.
join
(
__dirname
,
'
./src/
'
);
const
mergeLessPlugin
=
new
MergeLessPlugin
({
stylesDir
,
outFile
,
});
const
options
=
{
antDir
:
path
.
join
(
__dirname
,
'
./node_modules/antd
'
),
stylesDir
:
path
.
join
(
__dirname
,
'
./src/
'
)
,
stylesDir
,
varFile
:
path
.
join
(
__dirname
,
'
./node_modules/antd/lib/style/themes/default.less
'
),
mainLessFile
:
path
.
join
(
__dirname
,
'
./src/index.less
'
)
,
mainLessFile
:
outFile
,
themeVariables
:
[
'
@primary-color
'
],
indexFileName
:
'
index.html
'
,
};
const
themePlugin
=
new
AntDesignThemePlugin
(
options
);
// in config object
webpackConfig
.
plugins
.
push
(
mergeLessPlugin
);
webpackConfig
.
plugins
.
push
(
themePlugin
);
return
webpackConfig
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment