From b242f49e6798ac297a3dad0dfb03c0893e394464 Mon Sep 17 00:00:00 2001 From: Drew Powers Date: Mon, 2 Oct 2017 08:07:52 -0400 Subject: [PATCH] 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. --- README.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 570e6bb..24a4b88 100644 --- a/README.md +++ b/README.md @@ -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 you’d like to require Snap, use: +``` +import Snap from 'snapsvg'; ``` ### Build