-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(okam-build): add postcss-plugin-wx2swan
- Loading branch information
Showing
4 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/okam-build/lib/processor/css/postcss-plugin-wx2swan.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @file postcss plugin px2rpx | ||
* @author [email protected] | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const postcss = require('postcss'); | ||
const path = require('path'); | ||
|
||
module.exports = postcss.plugin('postcss-plugin-wx2swan', function (opts = {}) { | ||
|
||
let file = opts.file; | ||
|
||
return function (css, result) { | ||
css.walkAtRules(rule => { | ||
if (rule.name === 'import') { | ||
// path.resolve(file.fullPath, ); | ||
const depRelPath = rule.params.slice(1, -1); | ||
rule.params = rule.params.replace(/\.wxss/, '.css'); | ||
file.addDeps(depRelPath); | ||
} | ||
}); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/okam-build/lib/processor/wx2swan/wxssTransform.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @file The postcss processor | ||
* @author [email protected] | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const postcssProcessor = require('../css/postcss'); | ||
const wx2swanPlugin = require('../css/postcss-plugin-wx2swan'); | ||
|
||
module.exports = function (file, options) { | ||
let config = options.config; | ||
config.plugins = config.plugins || []; | ||
config.plugins.push(wx2swanPlugin.bind(this, {file})); | ||
return postcssProcessor(file, options); | ||
}; | ||
|