diff --git a/packages/okam-build/lib/processor/css/postcss-plugin-wx2swan.js b/packages/okam-build/lib/processor/css/postcss-plugin-wx2swan.js new file mode 100644 index 00000000..4b04e24b --- /dev/null +++ b/packages/okam-build/lib/processor/css/postcss-plugin-wx2swan.js @@ -0,0 +1,25 @@ +/** + * @file postcss plugin px2rpx + * @author xiaohong8023@outlook.com + */ + +'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); + } + }); + }; +}); diff --git a/packages/okam-build/lib/processor/helper/npm.js b/packages/okam-build/lib/processor/helper/npm.js index 01ba8667..e91a07e8 100644 --- a/packages/okam-build/lib/processor/helper/npm.js +++ b/packages/okam-build/lib/processor/helper/npm.js @@ -15,8 +15,6 @@ function isNpmModuleFile(modulePath) { function resolveNpmModuleNewPath(oldPath, rebaseDepDir) { let newPath = rebaseDepDir + oldPath.substr(DEP_DIR_NAME.length + 1); - // replace all `node_modles` to `npm` to fix weixin cannot find the module - // if the module path exists `node_module` dir name return nodeModulesToNpm(newPath); } diff --git a/packages/okam-build/lib/processor/wx2swan/index.js b/packages/okam-build/lib/processor/wx2swan/index.js index 8e4aec2a..274cd195 100644 --- a/packages/okam-build/lib/processor/wx2swan/index.js +++ b/packages/okam-build/lib/processor/wx2swan/index.js @@ -11,7 +11,7 @@ const wx2swanMap = { rext: 'swan' }, wxss: { - processor: null, + processor: require('./wxssTransform'), rext: 'css' }, js: { diff --git a/packages/okam-build/lib/processor/wx2swan/wxssTransform.js b/packages/okam-build/lib/processor/wx2swan/wxssTransform.js new file mode 100644 index 00000000..5d745429 --- /dev/null +++ b/packages/okam-build/lib/processor/wx2swan/wxssTransform.js @@ -0,0 +1,17 @@ +/** + * @file The postcss processor + * @author xiaohong8023@outlook.com + */ + +'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); +}; +