Skip to content

Commit 4b765a0

Browse files
committed
README: Document using resolve.alias for simpler paths
1 parent bd0d33c commit 4b765a0

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

README.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,33 @@ This writes resources into the `dist/` folder. They are not minified to make it
2525

2626
This demo is mostly useful to show how to use webpack to bundle a single page application that uses jQuery UI. The generated html page has no content on its own, which is a bad approach when you're building public facing websites. For those you'd start with a proper HTML page, but you could still use webpack to bundle the static resources (JS, CSS, images).
2727

28-
28+
## Using `resolve.alias` to simplify imports
29+
30+
The demo is currently using these paths to require the autocomplete widget and its required CSS:
31+
32+
```js
33+
require('jquery-ui/themes/base/core.css');
34+
require('jquery-ui/themes/base/menu.css');
35+
require('jquery-ui/themes/base/autocomplete.css');
36+
require('jquery-ui/themes/base/theme.css');
37+
var autocomplete = require('jquery-ui/ui/widgets/autocomplete');
38+
```
39+
40+
If you don't want to specify the `themes/base` and `ui/widgets` paths for every import, you can use webpack's [`resolve.alias`](https://webpack.github.io/docs/configuration.html#resolve-alias) configuration:
41+
42+
```js
43+
resolve: {
44+
alias: {
45+
'jquery-ui': 'jquery-ui/ui/widgets',
46+
'jquery-ui-css': 'jquery-ui/../../themes/base'
47+
}
48+
}
49+
```
50+
This specifies two aliases, one for widgets, one for CSS. With that in place, the code then looks like this:
51+
```js
52+
require('jquery-ui-css/core.css');
53+
require('jquery-ui-css/menu.css');
54+
require('jquery-ui-css/autocomplete.css');
55+
require('jquery-ui-css/theme.css');
56+
var autocomplete = require('jquery-ui/autocomplete');
57+
```

0 commit comments

Comments
 (0)