Code Monkey home page Code Monkey logo

Comments (11)

rubyboy avatar rubyboy commented on August 21, 2024

Few questions to direct this issue to the right place:

  1. Does it work if you don't minify the code?
  2. Try to mangling the code. Does that work?
  3. Do you get the same problem when you run the non-webpack minified version? (plain scripts imported in the HTML)

from angular2-materialize.

Arkanayan avatar Arkanayan commented on August 21, 2024
  1. Yes, It works when I don't minify.
  2. Yes, without any mangling, the code works fine.
  3. Yes, when I was testing without webpack, it worked.

I think if I exclude materialize.js from UglifyJsPlugin, it will work. But I think I wrote the regex wrong.

Also I noticed the files becomes significantly bigger on including MaterializeJs ( >1MB).

Is there a way to load the scripts (jquery, materialize.js) from cdn ? I tried with externals plugin. But it didn't work.

from angular2-materialize.

rubyboy avatar rubyboy commented on August 21, 2024

I tried minifiying the example app and it worked well when using JSPM. Here's the minified JS: http://angular2-materialize.surge.sh/index.js (the example app is here: http://angular2-materialize.surge.sh)

You can load the MaterializeCSS scripts directive like this:

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css">
    <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>

Which version of Angular2 are you using? During beta there were problems with minifying it. The reason I'm asking is that the problem you're getting it actually in the Angular code. In browser_adapter.js .

from angular2-materialize.

Arkanayan avatar Arkanayan commented on August 21, 2024

I am using angular 2 RC. If I include the script tags from cdn, won't there will be duplication ?

Once in webpack bundle, second time in index.html.

BTW the mangle problem is solved by adding materialize to the except list.

except: ['Materialize']

from angular2-materialize.

rubyboy avatar rubyboy commented on August 21, 2024

Is there a way to alias something to an empty return value in Webpack?
The import in angular2-materialize is global: https://github.com/InfomediaLtd/angular2-materialize/blob/master/src/index.ts#L1
So it doesn't expect anything to come back. Only expects "materialize" to point at something.

I can also create a different entry point for angular2-materialize that doesn't include the import. This way it stands on its own and you can import materialize separately (before angular2-materialize, though). Of that helps..

from angular2-materialize.

Arkanayan avatar Arkanayan commented on August 21, 2024

If I point 'materialize' to global 'Materialize and disable alias 'materialize' to local script,

 externals : {
    "materialize": "Materialize"
  },

and

    alias: {
      materializecss: 'materialize-css/dist/css/materialize.css',
      // materialize: 'materialize-css/dist/js/materialize.js',
  }

I am getting this error
ORIGINAL EXCEPTION: Error: Couldn't find materialize function ''tabs' on element or the global Materialize object.

from angular2-materialize.

rubyboy avatar rubyboy commented on August 21, 2024

It means that Materialize doesn't exist on the window. It hasn't been loaded.
Or, that it points to the wrong thing.

Try not having the external. Also, maybe alias materialize to the CSS as well.

from angular2-materialize.

rubyboy avatar rubyboy commented on August 21, 2024

@Arkanayan I've just read this on the Uglify documentation: "by default, UglifyJS will remove code that is obviously unreachable". Maybe it removed Materialize, thinking it's not used?

Can you try running your same setup with the following Uglify flag? --no-dead-code
It should disable the dead code elimination and then we'll know if this is what's causing Materialize to be removed from your prod build.

from angular2-materialize.

Arkanayan avatar Arkanayan commented on August 21, 2024

@rubyboy You are right. With dead code not removed, it works.

This is the config on webpack

  new UglifyJsPlugin({
      // beautify: true, //debug
      // mangle: false, //debug 
      // unused: false, //debug
      // deadCode: false, //debug
      // compress: {
      //   screw_ie8: true,
      //   keep_fnames: true,
      //   drop_debugger: false,
      //   dead_code: false,
      //   unused: false
      // }, // debug
      // comments: true, //debug

      beautify: false, //prod
      dead_code: false, //debug  

// If you want to remove dead code, uncomment this mangle block
/*      mangle: {
        except: ['Materialize']
      },
*/

/*
      mangle: {
        screw_ie8 : true,
        keep_fnames: true
      }, //prod
*/

      compress: {
        screw_ie8: true
      }, //prod

      exclude: ['/materialize.js/g'],
      comments: false //prod
    }),

from angular2-materialize.

Arkanayan avatar Arkanayan commented on August 21, 2024

You can close this issue, if you want.

from angular2-materialize.

rubyboy avatar rubyboy commented on August 21, 2024

Awesome. Thanks for checking and getting back to me. Much appreciated!

from angular2-materialize.

Related Issues (20)

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.