Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Webpack in an Ionic Version 1 app? (Is it possible/are there alternatives?)

Tags:

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?

like image 316
garrettmac Avatar asked May 03 '16 00:05

garrettmac


People also ask

What is webpack and how do you use it?

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.

How do I run a webpack locally?

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.

How do I find my webpack command line version?

Run the webpack-dev-server . Output the version number of webpack , webpack-cli and webpack-dev-server .


1 Answers

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

like image 69
Bogdan Savluk Avatar answered Sep 21 '22 17:09

Bogdan Savluk