All Projects → kotarella1110 → cordova-plugin-webpack

kotarella1110 / cordova-plugin-webpack

Licence: Apache-2.0 license
Integrate webpack into your Cordova workflow.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to cordova-plugin-webpack

cordova-gmv-barcode-scanner
A Cordova barcode scanning plugin based on the Google Mobile Vision library for iOS & Android.
Stars: ✭ 48 (-21.31%)
Mutual labels:  cordova, cordova-android, cordova-plugin, cordova-ios
cordova-plugin-flurryanalytics
Adds support for all that Flurry Analytics flavored goodness to your Cordova based apps
Stars: ✭ 23 (-62.3%)
Mutual labels:  cordova, cordova-android, cordova-plugin, cordova-ios
cordova-plugin-zeep
Zip compression/decompression for the cordova/phonegap platform
Stars: ✭ 27 (-55.74%)
Mutual labels:  cordova, cordova-android, cordova-plugin, cordova-ios
Create-a-custom-Cordova-plugin
How to create a custom cordova plugin and bridge it between your native code and a new or existing Cordova project
Stars: ✭ 32 (-47.54%)
Mutual labels:  cordova, cordova-android, cordova-plugin
JiaCordova
在Cordova及插件的基础上封装一些常用的功能,不断更新中
Stars: ✭ 35 (-42.62%)
Mutual labels:  cordova, cordova-plugin, cordova-ios
cordova-plugin-android-window-background
Simple Cordova plugin to set Android window background on start-up 🎨 🍭
Stars: ✭ 15 (-75.41%)
Mutual labels:  cordova, cordova-android, cordova-plugin
cordova-plugin-ironsource-ads
Cordova plugin for IronSource ads
Stars: ✭ 17 (-72.13%)
Mutual labels:  cordova-android, cordova-plugin, cordova-ios
cordova-plugin-today-widget
Add a today widget app extension target to your cordova project.
Stars: ✭ 51 (-16.39%)
Mutual labels:  cordova, cordova-plugin, cordova-ios
cordova-plugin-example
Example Cordova plugin for iOS and Android to support blog post.
Stars: ✭ 15 (-75.41%)
Mutual labels:  cordova-android, cordova-plugin, cordova-ios
Vue Objccn
🔥 Use Vue.js to develop a cross-platform full stack application / 用 Vue.js 开发的跨三端应用
Stars: ✭ 1,993 (+3167.21%)
Mutual labels:  cordova, cordova-ios
Cordova Plugin Touch Id
💅 👱‍♂️ Forget passwords, use a fingerprint scanner!
Stars: ✭ 209 (+242.62%)
Mutual labels:  cordova, cordova-plugin
cordova-fonts
Cordova plugin for enumerating fonts on a mobile device
Stars: ✭ 14 (-77.05%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Audioinput
This iOS/Android Cordova/PhoneGap plugin enables audio capture from the device microphone, by in near real-time forwarding audio to the web layer of your application. A typical usage scenario for this plugin would be to use the captured audio as source for a web audio node chain, where it then can be analyzed, manipulated and/or played.
Stars: ✭ 137 (+124.59%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Wkwebview File Xhr
Cordova Plugin for WebView File XHR
Stars: ✭ 116 (+90.16%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Fingerprint Aio
👆 📱 Cordova Plugin for fingerprint sensors (and FaceID) with Android and iOS support
Stars: ✭ 236 (+286.89%)
Mutual labels:  cordova, cordova-plugin
Cordova Plugin Add Swift Support
🔨 Swiftify your Cordova app !
Stars: ✭ 108 (+77.05%)
Mutual labels:  cordova, cordova-plugin
Wifiwizard2
A Cordova plugin for managing Wifi networks (new version of WiFiWizard) - Latest is version 3+
Stars: ✭ 106 (+73.77%)
Mutual labels:  cordova, cordova-plugin
cordova-plugin-downloadmanager
A Cordova plugin to download file in system's default download manager
Stars: ✭ 45 (-26.23%)
Mutual labels:  cordova, cordova-plugin
ZeroConf
ZeroConf plugin for Cordova/Phonegap 3.0
Stars: ✭ 39 (-36.07%)
Mutual labels:  cordova-android, cordova-plugin
cordova-study
📱 Cordova学习记录,Cordova插件的使用,热更新、media、device、集成x5内核等等。
Stars: ✭ 19 (-68.85%)
Mutual labels:  cordova, cordova-plugin

cordova-plugin-webpack

This plugin integrates webpack into your Cordova workflow.

All Contributors

License Actions Status NPM Version Downloads Month Downloads Total Commitizen friendly PRs Welcome

Motivation

Module bundlers such as webpack are essential for SPA (Single Page Application) development. Unfortunately, the Cordova workflow does not integrate webpack as a standard feature.

Simply install this plugin to easily integrate webpack into your Cordova workflow.

Demo

Demo

Features

  • Ability to have build scripts by webpack when you build or run Cordova app
  • Ability to have LiveReload (Hot Module Replacement) run by Webpack Dev Server when you’re testing on a device or emulator for Android and iOS

Supported Platforms

  • Browser
  • Android
  • iOS

Installation

$ npm install -D webpack@4 webpack-cli@3 webpack-dev-server@3
$ cordova plugin add cordova-plugin-webpack

CLI Reference

Syntax

$ cordova { prepare | platform add | build | run } [<platform> [...]]
    [-- [--webpack.<option> <value> | --livereload]]
Option Description Default Aliases
--webpack.<option> Passed to webpack-cli options or webpack-dev-server options. eg: --webpack.config example.config.js
Note: Some options such as Stats Options and Watch Options are not yet supported.
-w
--livereload Enables LiveReload (HMR) false -l

Examples

Build

Before preparing your Cordova app, build scripts by webpack.

$ cordova prepare
$ cordova build -- --webpack.config path/to/dir/webpack.config.js
$ cordova build android -- --webpack.mode=production
$ cordova build ios -- --webpack.env.prod

Live Reload (HMR)

After preparing your Cordova app, run LiveReload by Webpack Dev Server.

$ cordova prepare -- --livereload
$ cordova run ios -- -w.config path/to/dir/webpack.config.babel.js -l
$ cordova run android -- --livereload --webpack.port=8888 --webpack.watch-content-base=false

Usage

  1. Add this plugin

  2. Create a webpack configuration file (webpack.config.js) in your project root folder

    const path = require('path');
    
    module.exports = {
      mode: 'development',
      entry: './src/index.js',
      output: {
        path: path.resolve(__dirname, 'www'),
        filename: 'index.bundle.js',
      },
      devtool: 'inline-source-map',
    };
  3. Execute the commands

    $ cordova build
    $ cordova run -- --livereload
For more information...
  1. Create a Cordova app

    $ cordova create cordova-plugin-webpack-example cordova.plugin.webpack.example CordovaPluginWebpackExample
  2. Add platforms

    $ cd cordova-plugin-webpack-example
    $ cordova platform add android ios
  3. Add this plugin

  4. Create a JavaScript file (entry point)

    $ mkdir src
    $ mv www/js/index.js src/index.js
  5. Create a webpack configuration file (webpack.config.js) in your project root folder

    const path = require('path');
    
    module.exports = {
      mode: 'development',
      entry: './src/index.js',
      output: {
        path: path.resolve(__dirname, 'www'),
        filename: 'index.bundle.js',
      },
      devtool: 'inline-source-map',
    };
  6. Fix a HTML file (www/index.html)

    -         <script type="text/javascript" src="js/index.js"></script>
    +         <script type="text/javascript" src="index.bundle.js"></script>
  7. Execute the commands

    $ cordova build
    $ cordova run -- --livereload

NOTE

Starting with Android 9 (API level 28), cleartext support is disabled by default. Therefore, LiveReload does not work on Android 9.0 and higher devices and emulators. Also see this issue.

To resolve this, you must modify your config.xml file to enable cleartext support.

  1. Add xmlns:android="http://schemas.android.com/apk/res/android" in widget root element

    <widget id="cordova.plugin.webpack.example" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  2. Enable android:usesCleartextTraffic attribute in application element

    <platform name="android">
        <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:usesCleartextTraffic="true" />
        </edit-config>
    </platform>

Custom webpack configuration

Basically, it works according to your webpack configuration file. If you want to custom webpack configuration, modify your webpack.config.js file.

...
module.exports = {
  ...
  mode: 'production',
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'www'),
    filename: 'bundle.js',
  },
  plugins: [
    new HtmlWebpackPlugin(),
  ],
  ...
  devServer: {
    contentBase: path.join(__dirname, 'public'),
    host: 'localhost',
    port: '8000',
    hot: false,
  },
  ...
};
Option Default
devServer.contentBase www
devServer.historyApiFallBack true
devServer.host 0.0.0.0
devServer.port 8080
devServer.watchContentBase true
devServer.hot true

For example, if you want page reloading (LiveReload) instead of hot module reloading (HMR), specify the devServer.hot option as false.

...
module.exports = {
  ...
  devServer: {
    hot: false,
  },
  ...
};

Contribute

Contributions are always welcome! Please read the contributing first.

Contributors

Thanks goes to these wonderful people (emoji key):


Kotaro Sugawara

💻 📖 🤔 🚇 ⚠️

Jimmy Multani

📖 💻

shotaabe

📖 🎨

Gavin Henderson

🐛 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

License

Apache-2.0 © Kotaro Sugawara

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].