Skip to content

Commit e98cf26

Browse files
committed
Change readme for new webpack config
1 parent 5370142 commit e98cf26

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

README.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,54 +66,54 @@ we can automatically use this plugin for all HTTP calls in NativeScript that use
6666
* NativeScript image-cache
6767
* Any NativeScript plugin that uses above methods internally
6868

69-
The way to do this is quite simple, we only have to import a plugin and add the plugin to the `plugins` array in the webpack config. The easiest way to do this is by using a custom webpack config:
69+
The way to do this is quite simple, we only have to import a plugin and add the plugin to the webpack config.
7070

71-
Open `nativescript.config.ts`, and make sure that you have `webpackConfigPath` option. If you don't have it, add it and also create the webpack config path. Your `nativescript.config.ts` may look like this afterwards:
72-
```typescript
73-
import { NativeScriptConfig } from '@nativescript/core';
74-
75-
export default {
76-
id: 'org.nativescript.nativescripthttptest',
77-
appPath: 'src',
78-
appResourcesPath: 'App_Resources',
79-
android: {
80-
v8Flags: '--expose_gc',
81-
markingMode: 'none'
82-
}
83-
webpackConfigPath: './my-custom.webpack.config.js'
84-
} as NativeScriptConfig;
85-
```
86-
87-
Open the file that `webpackConfigPath` points to, in this case `my-custom.webpack.config.js`, if this file is empty, make it look like this:
71+
Open the file `webpack.config.js``, it may look like this:
8872
```javascript
89-
const webpackConfig = require("./webpack.config");
73+
const webpack = require("@nativescript/webpack");
74+
9075
module.exports = (env) => {
91-
// Here you can modify env before passing them to the default config
92-
const config = webpackConfig(env);
76+
webpack.init(env);
9377

94-
// Here you can modify everything created by the default configuration
95-
return config;
96-
}
78+
// Learn how to customize:
79+
// https://docs.nativescript.org/webpack
80+
81+
return webpack.resolveConfig();
82+
};
9783
```
9884

99-
Import our webpack implementation and add a line in the place where it says you can modify the default configuration, like this:
85+
Import our webpack implementation and add a line before `webpack.resolveConfig()`, like this:
10086

10187
```javascript
102-
const webpackConfig = require("./webpack.config");
88+
const webpack = require("@nativescript/webpack");
10389
const NativeScriptHTTPPlugin = require("@klippa/nativescript-http/webpack"); // Import NativeScriptHTTPPlugin
10490

10591
module.exports = (env) => {
106-
// Here you can modify env before passing them to the default config
107-
const config = webpackConfig(env);
92+
webpack.init(env);
10893

109-
config.plugins.push(new NativeScriptHTTPPlugin()); // Use NativeScriptHTTPPlugin
94+
// Learn how to customize:
95+
// https://docs.nativescript.org/webpack
11096

111-
// Here you can modify everything created by the default configuration
112-
return config;
113-
}
97+
webpack.chainWebpack(config => {
98+
config.plugin('NativeScriptHTTPPlugin').use(NativeScriptHTTPPlugin)
99+
});
100+
101+
return webpack.resolveConfig();
102+
};
114103
```
115104

116105
The `NativeScriptHTTPPlugin` can be given an object with the following properties: `replaceHTTP` (true/false) and `replaceImageCache` (true/false). This way you can control what the plugin replaces. If you don't give this options object we will replace both.
106+
The options can be passed like this:
107+
```javascript
108+
webpack.chainWebpack(config => {
109+
config.plugin('NativeScriptHTTPPlugin').use(NativeScriptHTTPPlugin, [
110+
{
111+
replaceHTTP: true,
112+
replaceImageCache: false
113+
}
114+
])
115+
});
116+
```
117117

118118
**Note: if you do this, you don't have to do the other integrations.**
119119

0 commit comments

Comments
 (0)