I've never used Webpack in an ionic project and I am trying to use it like I would in node.js
project and I'm getting the error
ReferenceError: Can't find variable: require
so I seems as though I wouldn't use webpack the same way. How can I do this in my Ionic version 1 project?
So far I add the bundle in my index.html
<script src="app/main/myapp.bundle.js"></script>
and inside I import all my other scripts
like so
require('../common/myimport')
removing the
<script src="app/common/myimport.js"></script>
in my index.html
Then if I run
webpack ./www/app/main/app.js ./www/app/main/myapp.bundle.js
I get that error.
So can I use webpack
in ionic, and if so how can I import my scripts into the bundle
?
Webpack is a static module bundler for JavaScript applications — it takes all the code from your application and makes it usable in a web browser. Modules are reusable chunks of code built from your app's JavaScript, node_modules, images, and the CSS styles which are packaged to be easily used in your website.
To run the local installation of webpack you can access its binary version as node_modules/. bin/webpack . Alternatively, if you are using npm v5. 2.0 or greater, you can run npx webpack to do it.
Run the webpack-dev-server . Output the version number of webpack , webpack-cli and webpack-dev-server .
Yes, you can. It is the same as for any angular 1.x application.
I have made project template for this purpose with all required configuration files for webpack:
https://github.com/zxbodya/angular-webpack-seed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With