-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Question] Use XrmQuery with Webpack #199
Comments
Did you ever figure anything more out on this? |
Yes, I tried for a couple of hours to setup webpack but without luck. I was able to bundle XrmQuery to the result files and everything works properly but I had a big problem with Intellisense, I couldn't use generated typings for my entities and I didn't understand why. Finally, we resigned from webpack and use only sparkle to build and release pipeline in the Cloud. |
I figured out how to do this. In your webpack.config add a ProvidePlugin definition to get the file to get loaded anywhere XrmQuery, Filter, or XQW are used. Also install exports-loader (npm install exports-loader --save-dev) and add settings to export out those variables.: const Webpack = require('webpack');
const Path = require('path');
module.exports = {
module: {
rules: [{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},{
test: require.resolve("./src/lib/dg.xrmquery.web.min"),
loader: "exports-loader",
options:{
exports: ["XrmQuery", "Filter", "XQW"]
}
},
],
},
plugins: [
new Webpack.ProvidePlugin({
XrmQuery: [Path.resolve(__dirname, "./src/lib/dg.xrmquery.web.min"), "XrmQuery"],
Filter: [Path.resolve(__dirname, "./src/lib/dg.xrmquery.web.min"), "Filter"],
XQW: [Path.resolve(__dirname, "./src/lib/dg.xrmquery.web.min"), "XQW"],
})
],
} this will force the file to get loaded in every file where it is referenced, without having to specify the import. Note sure if XQW is ever used, but it is only getting added if it is actually being used, so I think this problem is solved! Maybe @misoeli should add this to the docs? |
Regarding resolving types, this should be added to "typeRoots": [
"path/to/folder/where/xrmdefinitelytyped/definitions/are",
"./node_modules/@types"
], And @daryllabar answer should be accepted if we want to use XrmQuery with WebPack as-is. Here is another config if using from create-react-app and react-app-rewired. config-overrides.js const Path = require("path");
const Webpack = require('webpack');
const reactScriptsPaths = require('react-scripts/config/paths');
module.exports = {
webpack: function (config, env) {
//Add XrmDefinitelyTyped
let xrmDefinitelyTypedPlugin = new Webpack.ProvidePlugin({
XrmQuery: [Path.resolve(reactScriptsPaths.appNodeModules, "@deaccrm/xrmtypings/dg.xrmquery.web"), "XrmQuery"],
Filter: [Path.resolve(reactScriptsPaths.appNodeModules, "@deaccrm/xrmtypings/dg.xrmquery.web"), "Filter"],
XQW: [Path.resolve(reactScriptsPaths.appNodeModules, "@deaccrm/xrmtypings/dg.xrmquery.web"), "XQW"],
});
let xrmDefinitelyTypedExportsLoaderRule = {
test: require.resolve(Path.resolve(reactScriptsPaths.appNodeModules, "@deaccrm/xrmtypings/dg.xrmquery.web")),
loader: "exports-loader",
options:{
exports: ["XrmQuery", "Filter", "XQW"]
}
};
config.plugins.push(xrmDefinitelyTypedPlugin);
config.module.rules.push(xrmDefinitelyTypedExportsLoaderRule);
return config;
}
} |
Hello,
I would like to ask if there is any possibility to use XrmQuery with Webpack?
In each form where we use XrmQuery we need to add jslib to Form which is not very optimal.
I would like to use a Webpack to bundle TS script with XrmQuery and using Sparkle publish one script to Dynamics CRM.
I have tried to do this as follows:
Thank you in advance!
The text was updated successfully, but these errors were encountered: