Skip to content
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

[Feature]: less.additionalData 类型定义允许异步函数 #1375

Closed
claneo opened this issue Jan 20, 2024 · 1 comment · Fixed by #1377
Closed

[Feature]: less.additionalData 类型定义允许异步函数 #1375

claneo opened this issue Jan 20, 2024 · 1 comment · Fixed by #1377
Assignees

Comments

@claneo
Copy link

claneo commented Jan 20, 2024

What problem does this feature solve?

当前定义:

additionalData?:
| string
| ((
content: string,
loaderContext: LoaderContext<LessLoaderOptions>,
) => string);

less-loader 文档示例

module.exports = {
  module: {
    rules: [
      {
        test: /\.less$/i,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "less-loader",
            options: {
              additionalData: async (content, loaderContext) => {
                // More information about available properties https://webpack.js.org/api/loaders/
                const { resourcePath, rootContext } = loaderContext;
                const relativePath = path.relative(rootContext, resourcePath);

                if (relativePath === "styles/foo.less") {
                  return "@value: 100px;" + content;
                }

                return "@value: 200px;" + content;
              },
            },
          },
        ],
      },
    ],
  },
};

less-loader 代码:

https://github.com/webpack-contrib/less-loader/blob/c4928a3ffbb523e97822e6ed955a04b658164d0c/src/index.js#L50

What does the proposed API look like?

export type LessLoaderOptions = {
  lessOptions?: Less.Options;
  additionalData?:
    | string
    | ((
        content: string,
        loaderContext: LoaderContext<LessLoaderOptions>,
      ) => string | Promise<string>);
  sourceMap?: boolean;
  webpackImporter?: boolean;
  implementation?: unknown;
};
@chenjiahan chenjiahan self-assigned this Jan 20, 2024
@chenjiahan
Copy link
Member

感谢指正 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants