Skip to content

Commit 689f3c3

Browse files
committed
Fixes autoNumeric#29, autoNumeric#25 remove requirement of webpack alias for autonumeric dependency
1 parent ee37562 commit 689f3c3

File tree

6 files changed

+89
-112
lines changed

6 files changed

+89
-112
lines changed

README.md

-31
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ This means you **need** to link the [AutoNumeric](https://github.com/autoNumeric
3939
<script src="https://unpkg.com/autonumeric"></script>
4040
```
4141

42-
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:
43-
44-
```js
45-
module.exports = {
46-
entry : './src/vueAutonumericTest.js',
47-
output : {
48-
filename: './dist/bundle.js'
49-
},
50-
externals: {
51-
autonumeric: 'AutoNumeric',
52-
},
53-
};
54-
```
55-
5642
#### ...or by importing it directly as an ES6 module
5743

5844
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:
@@ -76,23 +62,6 @@ export default {
7662
}
7763
```
7864

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:
82-
```js
83-
module.exports = {
84-
entry : './src/vueAutonumericTest.js',
85-
output : {
86-
filename: './dist/bundle.js'
87-
},
88-
resolve: {
89-
alias: {
90-
AutoNumeric: 'node_modules/autonumeric/dist/autoNumeric.min',
91-
},
92-
},
93-
};
94-
```
95-
9665
### How to use?
9766

9867
The AutoNumeric component can be instantiated the same way `AutoNumeric` can.

build/webpack.base.js

-27
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,4 @@ module.exports = {
6767
children: false,
6868
timings : true,
6969
},
70-
71-
externals: {
72-
// This prevent bundling the AutoNumeric library inside the vue-autonumeric component
73-
// cf. https://webpack.js.org/configuration/externals/
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',
96-
},
9770
};

build/webpack.dist.js

+20
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ config.plugins = config.plugins.concat([
3737
}),
3838
]);
3939

40+
config.externals = {
41+
// This prevent bundling the AutoNumeric library inside the vue-autonumeric component
42+
// cf. https://webpack.js.org/configuration/externals/
43+
/*
44+
* Important note:
45+
* We need to setup root to use global variable here, since we want the user to be able to just use a
46+
* CDN link to the AutoNumeric library and make sure `vue-autonumeric` will correctly use this
47+
* (since it's exported as `AutoNumeric`, with this case).
48+
*
49+
* However if you are using `vue-autonumeric` in an ES6 module setup with a bundling tool
50+
* (ie. Webpack), then it should still import 'autonumeric' with this case from your node_modules.
51+
*/
52+
autonumeric: {
53+
commonjs2: 'autonumeric',
54+
commonjs: 'autonumeric',
55+
amd: 'autonumeric',
56+
root: '_', // indicates global variable 'AutoNumeric'
57+
},
58+
};
59+
4060
if (options.isProduction) {
4161
// Production only
4262
config.plugins = config.plugins.concat([

0 commit comments

Comments
 (0)