npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-webpack

v1.0.5

Published

Cordova Webpack Plugin

Downloads

395

Readme

All Contributors

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
  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):

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

License

Apache-2.0 © Kotaro Sugawara