Output webpack to a Cordova app.
var CordovaPlugin = require('webpack-cordova-plugin');
new CordovaPlugin({
config: 'config.xml', // Location of Cordova' config.xml (will be created if not found)
src: 'index.html', // Set entry-point of cordova in config.xml
platform: 'ios', (or 'android') // Set `webpack-dev-server` to correct `contentBase` to use Cordova plugins.
version: true, // Set config.xml' version. (true = use version from package.json)
});
- Install
cordova
and thewebpack-cordova-plugin
npm install -g cordova
npm install --save-dev webpack-cordova-plugin
-
Add the plugin to your
webpack.config.js
-
Run
webpack
. It wil automatically create the Cordovaconfig.xml
. -
Modify the app bundle ID in
config.xml
-
Launch cordova!
cordova platforms add ios # or android cordova run ios
In order for Cordova to load correctly, your index.html
must explictly refer to the cordova.js
script.
-
Create an
index.html
and make sure this is copied to your output:require('file?name=index.html!./index.html');
-
Include the
cordova.js
script in your index.html:<script type="text/javascript" src="cordova.js"></script>
--output-path
is set to the correctwww
directory.cordova.js
is declared as external.cordova.js
is loaded as script.config.xml
is updated (version and entry-point)--content-base
is updated to the correct platform (e.g./platforms/android/assets/www
)
- Enabled
platform
configuration and commandline option to set correct content base of dev server. - Cordova is installed in
process.cwd()
rather than thecontext
.
- added
www
as required cordova directory
- Added
script-loader
as peer dependency.