Giter Club home page Giter Club logo

nativescript-webpack-import-replace's Introduction

ImportReplacePlugin

NativeScript webpack plugin to rewrite various imports with the .ios or .android platform suffix to allow various Angular Components, Directives, or Pipes to properly AoT compile when building a NativeScript for Angular app.

Install

npm install nativescript-webpack-import-replace --save-dev

Usage

In your app's webpack.config.js, add the following:

function getPlugins(platform, env) {
    let plugins = [
      ...
      new ImportReplacePlugin({
          debug: true, // optional - outputs results
          platform: platform,
          files: [
              'slider.directive'
          ]
      }),
      ...

The files collection can be a list of import filenames you'd like replaced with the target platform suffix. The plugin will find the import and add the proper platform ending to the import to allow a proper AoT compile of your NativeScript for Angular app.

What does this solve?

When using nativescript-dev-webpack plugin with NativeScript for Angular project and you are using platform specific Components, Directives or Pipes, you may run into this type of bundling error:

ERROR in Unexpected value 'CustomDirective in /path/to/YourApp/app/your-folders/custom.directive.d.ts' declared by the module 'YourModule in /path/to/YourApp/app/your-folders/custom.module.ts'. Please add a @Pipe/@Directive/@Component annotation.

In this case, you can add this plugin to your config and designate the name of the import file to adjust to solve the error.

Learn why this exists?

The development and reason for the creation of this plugin will be featured in an upcoming "NativeScript for Angular" book published via Packt Publishing in the Fall 2017.

CREDITS

Huge thank you to Stanimira Vlaeva and Alex Vakrilov.

LICENSE

MIT

nativescript-webpack-import-replace's People

Contributors

nathanwalker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nativescript-webpack-import-replace's Issues

Question: Platform-specific template within node_modules

I abstracted a couple of my components into NgModules and moved them into their separate repo.
The issue is that they contain platform-specific template files and webpack isn't bundling them since its looking for a single .html file.

Any pointers?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.