Skip to content

Commit fe4df9e

Browse files
Fixes #18 Require of AutoNumeric is ES6 module and not the distribution version
Fix how using vue-autonumeric with a CDN did not work since the external library it searched was in lowercase. Update the documentation about using `vue-autonumeric` in an ES6 module setup with Webpack Important note: - We need to use `<npmPath>: 'AutoNumeric'` in the `vue-autonumeric`'s webpack configuration since we want the user to be able to just use a CDN link to the AutoNumeric library and make sure `vue-autonumeric` will correctly use this name (since it's exported as `AutoNumeric`, with this case). - However if you are using `vue-autonumeric` in an ES6 module setup with a bundling tool (ie. Webpack), then you'll need to declare in your project an alias so that Webpack will know how to recognize the correct library name case. - The alias configuration example for Webpack: ```js resolve: { extensions: ['.js', '.vue', '.json'], alias : { '~' : resolve('node_modules'), '@' : resolve('src'), 'AutoNumeric': resolve('node_modules/autonumeric/dist/autoNumeric.min'), }, }, ``` Signed-off-by: Alexandre Bonneau <[email protected]>
1 parent b63085a commit fe4df9e

File tree

8 files changed

+67
-30
lines changed

8 files changed

+67
-30
lines changed

CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
## Changelog for vue-autoNumeric
22

3+
### 1.2.4
4+
+ Fixes #18 Require of AutoNumeric is ES6 module and not the distribution version
5+
+ Fix how using vue-autonumeric with a CDN did not work since the external library it searched was in lowercase.
6+
+ Update the documentation about using `vue-autonumeric` in an ES6 module setup with Webpack
7+
8+
Important note:
9+
+ We need to use `<npmPath>: 'AutoNumeric'` in the `vue-autonumeric`'s webpack configuration since we want the user to be able to just use a CDN link to the AutoNumeric library and make sure `vue-autonumeric` will correctly use this name (since it's exported as `AutoNumeric`, with this case).
10+
+ However if you are using `vue-autonumeric` in an ES6 module setup with a bundling tool (ie. Webpack), then you'll need to declare in your project an alias so that Webpack will know how to recognize the correct library name case.
11+
+ The alias configuration example for Webpack:
12+
```js
13+
resolve: {
14+
extensions: ['.js', '.vue', '.json'],
15+
alias : {
16+
'~' : resolve('node_modules'),
17+
'@' : resolve('src'),
18+
'AutoNumeric': resolve('node_modules/autonumeric/dist/autoNumeric.min'),
19+
},
20+
},
21+
```
22+
323
### 1.2.3
424
+ Fixes #15 Prop Validation Returns Error if Empty String
525
+ Fixes #16 build fails on linux

README.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module.exports = {
5353
};
5454
```
5555

56-
#### ...or by importing it directly as a module
56+
#### ...or by importing it directly as an ES6 module
5757

5858
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:
5959

@@ -73,16 +73,12 @@ export default {
7373
components: {
7474
VueAutonumeric,
7575
},
76-
77-
data() {
78-
return {
79-
//
80-
};
81-
},
8276
}
8377
```
8478

85-
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:
79+
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**, otherwise Webpack will complain about the npm package `autonumeric` case.
80+
81+
The alias that you need to declare in your Webpack configuration:
8682
```js
8783
module.exports = {
8884
entry : './src/vueAutonumericTest.js',
@@ -91,7 +87,7 @@ module.exports = {
9187
},
9288
resolve: {
9389
alias: {
94-
AutoNumeric: 'autonumeric/dist/autoNumeric.min',
90+
AutoNumeric: 'node_modules/autonumeric/dist/autoNumeric.min',
9591
},
9692
},
9793
};

build/webpack.base.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ module.exports = {
7171
externals: {
7272
// This prevent bundling the AutoNumeric library inside the vue-autonumeric component
7373
// cf. https://webpack.js.org/configuration/externals/
74-
autonumeric: 'autonumeric',
74+
//XXX Note: You need to use `<npmPath>: 'AutoNumeric'` if you want to be able to just use a script CDN link to the AutoNumeric library, since it's exported as `AutoNumeric` (with this case) //FIXME But what happens when the user do not use a script link but directly import 'AutoNumeric' with `import AutoNumeric from 'autonumeric'`?
75+
/*
76+
* Important note:
77+
* We need to use `<npmPath>: 'AutoNumeric'` here since we want the user to be able to just use a
78+
* CDN link to the AutoNumeric library and make sure `vue-autonumeric` will correctly use this
79+
* name (since it's exported as `AutoNumeric`, with this case).
80+
*
81+
* However if you are using `vue-autonumeric` in an ES6 module setup with a bundling tool
82+
* (ie. Webpack), then you'll need to declare in your project an alias so that Webpack will know
83+
* how to recognize the correct library name case.
84+
*
85+
* The alias configuration example for Webpack:
86+
* resolve: {
87+
* extensions: ['.js', '.vue', '.json'],
88+
* alias : {
89+
* '~' : resolve('node_modules'),
90+
* '@' : resolve('src'),
91+
* 'AutoNumeric': resolve('node_modules/autonumeric/dist/autoNumeric.min'),
92+
* },
93+
* },
94+
*/
95+
'autonumeric/dist/autoNumeric.min': 'AutoNumeric',
7596
},
7697
};

dist/vue-autonumeric.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
2-
* vue-autonumeric v1.2.3 (https://github.com/autoNumeric/vue-autoNumeric)
2+
* vue-autonumeric v1.2.4 (https://github.com/autoNumeric/vue-autoNumeric)
33
* © 2018 Alexandre Bonneau <[email protected]>
44
* Released under the MIT License.
55
*/
66
(function webpackUniversalModuleDefinition(root, factory) {
77
if(typeof exports === 'object' && typeof module === 'object')
8-
module.exports = factory(require("autonumeric"));
8+
module.exports = factory(require("AutoNumeric"));
99
else if(typeof define === 'function' && define.amd)
10-
define("VueAutonumeric", ["autonumeric"], factory);
10+
define("VueAutonumeric", ["AutoNumeric"], factory);
1111
else if(typeof exports === 'object')
12-
exports["VueAutonumeric"] = factory(require("autonumeric"));
12+
exports["VueAutonumeric"] = factory(require("AutoNumeric"));
1313
else
14-
root["VueAutonumeric"] = factory(root["autonumeric"]);
14+
root["VueAutonumeric"] = factory(root["AutoNumeric"]);
1515
})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_43__) {
1616
return /******/ (function(modules) { // webpackBootstrap
1717
/******/ // The module cache
@@ -306,9 +306,9 @@ var _assign = __webpack_require__(16);
306306

307307
var _assign2 = _interopRequireDefault(_assign);
308308

309-
var _autonumeric = __webpack_require__(43);
309+
var _autoNumeric = __webpack_require__(43);
310310

311-
var _autonumeric2 = _interopRequireDefault(_autonumeric);
311+
var _autoNumeric2 = _interopRequireDefault(_autoNumeric);
312312

313313
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
314314

@@ -397,7 +397,7 @@ exports.default = {
397397
options = this.manageOptionElement(this.options);
398398
}
399399

400-
this.anElement = new _autonumeric2.default(this.$refs.autoNumericElement, options);
400+
this.anElement = new _autoNumeric2.default(this.$refs.autoNumericElement, options);
401401
if (this.value !== null && this.value !== '') {
402402
this.anElement.set(this.value);
403403

@@ -424,7 +424,7 @@ exports.default = {
424424
manageOptionElement: function manageOptionElement(optionElement) {
425425
var options = void 0;
426426
if (typeof optionElement === 'string' || optionElement instanceof String) {
427-
options = _autonumeric2.default.getPredefinedOptions()[optionElement];
427+
options = _autoNumeric2.default.getPredefinedOptions()[optionElement];
428428
if (options === void 0 || options === null) {
429429
console.warn('The given pre-defined options [' + optionElement + '] is not recognized by AutoNumeric.\nSwitching back to the default options.');
430430
options = defaultOptions;
@@ -446,9 +446,9 @@ exports.default = {
446446

447447
var optionsToUse = void 0;
448448
if (Array.isArray(newValue.options)) {
449-
optionsToUse = _autonumeric2.default.mergeOptions(newValue.options);
449+
optionsToUse = _autoNumeric2.default.mergeOptions(newValue.options);
450450
} else {
451-
optionsToUse = _autonumeric2.default._getOptionObject(newValue.options);
451+
optionsToUse = _autoNumeric2.default._getOptionObject(newValue.options);
452452
}
453453

454454
this.anElement.update(optionsToUse);

dist/vue-autonumeric.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-autonumeric",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "An AutoNumeric wrapper for Vue.js",
55
"author": "Alexandre Bonneau <[email protected]>",
66
"license": "MIT",
@@ -39,7 +39,7 @@
3939
"components"
4040
],
4141
"dependencies": {
42-
"autonumeric": "^4.2.12"
42+
"autonumeric": "^4.2.13"
4343
},
4444
"devDependencies": {
4545
"autoprefixer": "^6.7.7",

src/components/VueAutonumeric.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!--
22
vue-autonumeric
33

4-
@version 1.2.3
5-
@date 2018-05-09 UTC 21:30
4+
@version 1.2.4
5+
@date 2018-05-25 UTC 19:30
66

77
@author Alexandre Bonneau
88
@copyright 2018 © Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
@@ -38,7 +38,7 @@ OTHER DEALINGS IN THE SOFTWARE.
3838
-->
3939

4040
<script type="text/babel">
41-
import AutoNumeric from 'autonumeric';
41+
import AutoNumeric from 'autonumeric/dist/autoNumeric.min';
4242

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

yarn.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,9 @@ atob@^2.0.0:
331331
version "2.0.3"
332332
resolved "https://registry.yarnpkg.com/atob/-/atob-2.0.3.tgz#19c7a760473774468f20b2d2d03372ad7d4cbf5d"
333333

334-
autonumeric@^4.2.12:
335-
version "4.2.12"
336-
resolved "https://registry.yarnpkg.com/autonumeric/-/autonumeric-4.2.12.tgz#0d5cefc9ec36f0e625231462c64bed245b149f79"
334+
autonumeric@^4.2.13:
335+
version "4.2.13"
336+
resolved "https://registry.yarnpkg.com/autonumeric/-/autonumeric-4.2.13.tgz#29a1374fd16f91a60ba3d97fc74374a3d0057957"
337337

338338
autoprefixer@^6.3.1, autoprefixer@^6.7.7:
339339
version "6.7.7"

0 commit comments

Comments
 (0)