Comments (11)
Few questions to direct this issue to the right place:
- Does it work if you don't minify the code?
- Try to mangling the code. Does that work?
- Do you get the same problem when you run the non-webpack minified version? (plain scripts imported in the HTML)
from angular2-materialize.
- Yes, It works when I don't minify.
- Yes, without any mangling, the code works fine.
- 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.
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.
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.
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.
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.
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.
@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.
@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.
You can close this issue, if you want.
from angular2-materialize.
Awesome. Thanks for checking and getting back to me. Much appreciated!
from angular2-materialize.
Related Issues (20)
- Callback function for onCloseEnd parameter is always being invoked HOT 1
- Project seems unmaintained HOT 3
- unable to use MzToastModule HOT 1
- How do I upgrade this to Angular 6? keep getting type definition error
- checkbox needs doubleclick to uncheck
- Carousel does not load data from service
- Using default html elements HOT 2
- Sidenav did not close
- Checkbox - indeterminate state HOT 1
- Uncaught Error: Template parse errors: Can't bind to 'materializeActions' since it isn't a known property of 'div'. HOT 1
- Uncaught Error: Couldn't find Materialize object on window HOT 13
- Javascript components are unstable
- Select from angular2-material does not work when loading data from an observable
- Datepicker and Select immediately closing on open HOT 21
- How to add carousel-item after http request
- When Router changes the page the materialize module.js stops working
- material_select multiple problem after reset
- want to use in angular 9
- how to use modal that can be reused in other components
- Don't open/show my modal, when I try to open, the modal doesn't show and the button doesn't any action. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular2-materialize.