@nativescript-community/xml-ui-loader
这是一个 webpack loader,作为编译器在构建阶段将 XML 内容转换为 JavaScript。
npm i --save @nativescript-community/xml-ui-loader

@nativescript-community/xml-ui-loader

npm npm

此 loader 为在 Webpack 中使用 @nativescript-community/xml-ui-compiler 提供支持。

安装

npm install @nativescript-community/xml-ui-loader --save-dev

用法

webpack.config.js

const webpack = require('@nativescript/webpack');
const { getEntryDirPath, getPlatformName } = require('@nativescript/webpack/dist/helpers/platform');
const { chainLoaderConfiguration } = require("@nativescript-community/xml-ui-loader/helpers");

module.exports = (env) => {
webpack.init(env);

// Learn how to customize:
// https://docs.nativescript.cn/webpack

webpack.chainWebpack((config) => {
chainLoaderConfiguration(config, {
appPath: getEntryDirPath(),
platform: getPlatformName()
});
});

return webpack.resolveConfig();
};

还有一些预处理选项,对于应用输出自定义很有用。

chainLoaderConfiguration(config, {
appPath: getEntryDirPath(),
platform: getPlatformName(),
useDataBinding: false, // Set this to false if you don't want to use data binding system
preprocess: {
// Format attribute value
attributeValueFormatter: (value, attributeName, tagName, attributes) => value.toUpperCase(),
// Manage AST result
transformAst: (ast, generateFunc) => generateFunc(ast).code,
}
});