Update webpack install instructions (#551)

* Update webpack install instructions

This updates the older webpack instructions to work in a friendlier, more invisible way. Until Snap is updated to a more ES6-import-friendly format.

* Fix README syntax errors

This fixes some basic syntax errors in the webpack config fix.
master
Drew Powers 2017-10-02 08:07:52 -04:00 committed by Dmitry Baranovskiy
parent d8f7508872
commit b242f49e67
1 changed files with 21 additions and 2 deletions

View File

@ -27,9 +27,28 @@ In your HTML file, load simply by:
```
No other scripts are needed. Both the minified and uncompressed (for development) versions are in the `/dist` folder.
To load with webpack use following command:
#### webpack
To load with webpack 2.x and 3.x, install [Imports Loader](https://github.com/webpack-contrib/imports-loader) (`npm i -D imports-loader`), and add the following to your webpack config:
```js
const Snap = require(`imports-loader?this=>window,fix=>module.exports=0!snapsvg/dist/snap.svg.js`);
module: {
rules: [
{
test: require.resolve('snapsvg/dist/snap.svg.js'),
use: 'imports-loader?this=>window,fix=>module.exports=0',
},
],
},
resolve: {
alias: {
snapsvg: 'snapsvg/dist/snap.svg.js',
},
},
```
Then, in any module youd like to require Snap, use:
```
import Snap from 'snapsvg';
```
### Build