In our custom module, we have pages similar to the order page. We need some changes in the scripts.js file only in those custom module pages. Following is the core file we are using is
module-sales/view/adminhtml/web/order/create/scripts.js .
In order to override we added requirejs-config.js in the following location
app/code/[Namespace]/[Module]/view/adminhtml/requirejs-config.js
with the following content
var config = {
 map: {
 '*': {
 'Magento_Sales/order/create/scripts': 'Namespace_Module/js/scripts',
 }
 }
};
We copied the scripts.js file in the custom file scripts.js in the following location
Namespace/Module/view/adminhtml/web/js/scripts.js
The custom module pages are working as we expected. But the modifications are affecting not only in custom module pages but also in the Magento pages also.
Please, can anyone help?
- 
 so you want to do for both or only your page?Sunil Patel– Sunil Patel2017年11月29日 06:58:21 +00:00Commented Nov 29, 2017 at 6:58
- 
 @SunilPatel I want to do it for only my page.coderunner– coderunner2017年11月29日 07:04:21 +00:00Commented Nov 29, 2017 at 7:04
- 
 1you can create js and initialize your js for only your page so it will work, don't override itSunil Patel– Sunil Patel2017年11月29日 07:29:57 +00:00Commented Nov 29, 2017 at 7:29
- 
 1@SunilPatel Can you please guide on how to do it?coderunner– coderunner2017年11月29日 07:31:57 +00:00Commented Nov 29, 2017 at 7:31
- 
 can i know which type of modification you did? because if you intilize other js then you need to call that js from phtml file and i checked it is contain lot of filesSunil Patel– Sunil Patel2017年11月29日 07:39:23 +00:00Commented Nov 29, 2017 at 7:39
1 Answer 1
When you are overriding script.js using requirejs-config.js it's not only works for your custom module but whenever that core script.js will be called your custom js will be called instead od core script.js.
So if you want to use that script.js code into your custom module only, You have to create your own custom js same as script.js because override means you replaced js code with your own js for whole Magento.
'Magento_Sales/order/create/scripts': 'Namespace_Module/js/scripts', means you are overriding core js file so when Magento tries to call Magento_Sales/order/create/scripts, your 'Namespace_Module/js/scripts will be called.
If you want to create your own js file you have to give custom reference name to your js file in requirejs-config.js like:
'myscript': 'Namespace_Module/js/scripts',
- 
 That is what I have done. I have created my own script.js. However, the core file is also taking my JS file.coderunner– coderunner2017年11月29日 07:05:40 +00:00Commented Nov 29, 2017 at 7:05
- 
 you have not created your own js, You have overridden core jsRonak Chauhan– Ronak Chauhan2017年11月29日 07:06:39 +00:00Commented Nov 29, 2017 at 7:06
- 
 1'Magento_Sales/order/create/scripts': 'Namespace_Module/js/scripts',this will override js not create new jsRonak Chauhan– Ronak Chauhan2017年11月29日 07:07:13 +00:00Commented Nov 29, 2017 at 7:07
- 
 1to create your own js you have to give your custom reference to your js like: 'myscript': 'Namespace_Module/js/scripts',Ronak Chauhan– Ronak Chauhan2017年11月29日 07:07:59 +00:00Commented Nov 29, 2017 at 7:07
- 
 1copy code of the core file into your custom js file that is not the proper way but have to bind all things which used in core js and use it properly.Ronak Chauhan– Ronak Chauhan2017年11月29日 07:18:47 +00:00Commented Nov 29, 2017 at 7:18