-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bundless 模式下更改scss 或者less路径 #679
Comments
暂不支持,非 js 文件目前均直接输出不做处理,只能先用相对路径 |
可以自己写一个 plugin 处理: import type { IApi } from 'father';
import { addLoader, ILoaderItem } from 'father/dist/builder/bundless/loaders';
export default async (api: IApi) => {
const loaders: ILoaderItem[] = await api.applyPlugins({
key: 'addPostcssLoader',
initialValue: [
{
key: 'father-postcss-loader',
test: /\.(le|c)ss$/,
loader: require.resolve('./loader'),
},
],
});
loaders.forEach((loader) => addLoader(loader));
}; loader.js const postcss = require('postcss');
const syntax = require('postcss-less');
const atImport = require('postcss-import');
const autoprefixer = require('autoprefixer');
const loader = function (content) {
const cb = this.async();
postcss([
autoprefixer({
overrideBrowserslist: ['last 10 versions'],
}),
atImport({
resolve: (id) => {
if (id.startsWith('@')) {
console.log(this.resource)
// your code
}
return id
},
}),
])
.process(content, { syntax })
.then((result) => {
cb(null, result.content);
})
.catch(cb);
};
module.exports = loader; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
father4.0 打包模块用Bundless模式,只处理.js .ts 文件,但有些scss,或者less 文件在做引入的时候通过
这种方式引入文件,编译后要把
@
换成相对路径,这块要怎么支持呢The text was updated successfully, but these errors were encountered: