Skip to content

Commit 42efe4d

Browse files
Fix the component size issue which bundled the whole AutoNumeric library
Update the documentation with how to install the component, depending if the AutoNumeric library should be bundled or not Signed-off-by: Alexandre Bonneau <[email protected]>
1 parent a4a27ab commit 42efe4d

File tree

9 files changed

+78
-163
lines changed

9 files changed

+78
-163
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog for vue-autoNumeric
22

3+
### 1.0.4
4+
+ Fix the component size issue which bundled the whole `AutoNumeric` library
5+
+ Update the documentation with how to install the component, depending if the AutoNumeric library should be bundled or not
6+
37
### 1.0.3
48
+ Fix importing issues with the `AutoNumeric` library
59
+ Complete the documentation on how to install and use the component

README.md

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## vue-autoNumeric
22

3-
A Vue.js component that wraps the awesome autoNumeric input formatter library
3+
A Vue.js component that wraps the awesome [AutoNumeric](https://github.com/autoNumeric/autoNumeric/) input formatter library
44

55
[![NPM][nodei-image]][nodei-url]
66
<br>
@@ -12,7 +12,7 @@ Get in touch on [![Gitter chat][gitter-image]][gitter-url]
1212

1313
---
1414

15-
vue-autoNumeric wraps the awesome autoNumeric library and generate an `<input>` element managed by [AutoNumeric](https://github.com/autoNumeric/autoNumeric/).
15+
vue-autoNumeric wraps the awesome AutoNumeric library and generate an `<input>` element managed by [AutoNumeric](https://github.com/autoNumeric/autoNumeric/).
1616

1717
**Checkout the [demo](https://codepen.io/AnotherLinuxUser/pen/pWgOrZ?editors=1010)!**
1818

@@ -28,28 +28,71 @@ npm install vue-autonumeric --save
2828

2929
This means you **need** to link the [AutoNumeric](https://github.com/autoNumeric/autoNumeric/) library with either ways:
3030

31-
#### ...in your html `<head>` tag
32-
In the html `<head>` tag directly, or by using a CDN like so:
31+
#### ...in your html `<head>` tag directly
3332

3433
```html
34+
<!-- locally... -->
3535
<script src="../node_modules/autonumeric/dist/autonumeric.min.js"></script>
36-
<!-- or -->
37-
<script src="//unpkg.com/autonumeric"></script>
36+
<!-- ...or by using a CDN -->
37+
<script src="https://unpkg.com/autonumeric"></script>
38+
```
39+
40+
Then you need to tell Webpack to treat the `AutoNumeric` dependency as [external](https://webpack.js.org/configuration/externals/) so that it does not try to bundle it.<br>Here is a really simple `webpack.config.js` example that does that:
41+
42+
```js
43+
module.exports = {
44+
entry : './src/vueAutonumericTest.js',
45+
output : {
46+
filename: './dist/bundle.js'
47+
},
48+
externals: {
49+
AutoNumeric: 'AutoNumeric',
50+
},
51+
};
3852
```
3953

4054
#### ...or by importing it directly as a module
41-
You can choose to directly import the `AutoNumeric` library in your source code using:
55+
56+
You can choose to directly import the AutoNumeric library in your source code.<br>First, install the `autonumeric` dependency so that Webpack can find it using:
4257

4358
```sh
4459
yarn add autonumeric
4560
# or
4661
npm install autonumeric --save
4762
```
4863

49-
You'll then be able to use the `vue-autonumeric` component in your scripts using:
64+
You will as usual be able to use the `vue-autonumeric` component in your Vue components using:
65+
```js
66+
import VueAutonumeric from '../src/components/VueAutonumeric.vue';
67+
68+
export default {
69+
name : 'myComponent',
70+
71+
components: {
72+
VueAutonumeric,
73+
},
74+
75+
data() {
76+
return {
77+
//
78+
};
79+
},
80+
}
81+
```
82+
83+
However, when doing that if you want to be able to bundle all the scripts together with Webpack, you'll need to define an alias for the `AutoNumeric` library in your Webpack config like so:
5084
```js
51-
import AutoNumeric from 'autonumeric';
52-
import VueAutonumeric from 'vue-autonumeric';
85+
module.exports = {
86+
entry : './src/vueAutonumericTest.js',
87+
output : {
88+
filename: './dist/bundle.js'
89+
},
90+
resolve: {
91+
alias: {
92+
AutoNumeric: 'autonumeric/dist/autoNumeric.min',
93+
},
94+
},
95+
};
5396
```
5497

5598
### How to use?

build/webpack.base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ module.exports = {
7171
externals: {
7272
// This prevent bundling the AutoNumeric library inside the vue-autornumeric component
7373
// cf. https://webpack.js.org/configuration/externals/
74-
AutoNumeric: 'autonumeric',
74+
AutoNumeric: 'AutoNumeric',
7575
},
7676
};

dist/vue-autonumeric.js

Lines changed: 12 additions & 145 deletions
Large diffs are not rendered by default.

dist/vue-autonumeric.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/examples.bundle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
</head>
2222
<body>
2323
<div id="app"></div>
24+
<script src="https://unpkg.com/autonumeric"></script>
2425
<script src="examples.bundle.js"></script>
2526
</body>
2627
</html>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-autonumeric",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "An AutoNumeric wrapper for Vue.js",
55
"author": "Alexandre Bonneau <[email protected]>",
66
"license": "MIT",

src/components/VueAutonumeric.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!--
22
vue-autonumeric
33

4-
@version 1.0.3
5-
@date 2017-09-19 UTC 08:00
4+
@version 1.0.4
5+
@date 2017-11-29 UTC 20:00
66

77
@author Alexandre Bonneau
88
@copyright 2016 © Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
@@ -54,7 +54,7 @@ OTHER DEALINGS IN THE SOFTWARE.
5454
</template>
5555

5656
<script type="text/babel">
57-
import AutoNumeric from 'autonumeric';
57+
import AutoNumeric from 'AutoNumeric';
5858

5959
// Custom default autoNumeric option can be set here to override the default autoNumeric ones
6060
const defaultOptions = {};

0 commit comments

Comments
 (0)