Skip to content

Commit 7ac643e

Browse files
committed
feat: simplify webpack usage
You can now use Webpack loader using "svgr/webpack".
1 parent 039f2cb commit 7ac643e

6 files changed

Lines changed: 16 additions & 7 deletions

File tree

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
!/lib/*.js
33
!/bin/svgr
44
*.test.js
5+
!/webpack.js

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ module.exports = {
202202
rules: [
203203
{
204204
test: /\.svg$/,
205-
use: ['babel-loader', 'svgr/lib/webpack'],
205+
use: ['babel-loader', 'svgr/webpack'],
206206
},
207207
],
208208
},
@@ -220,7 +220,7 @@ module.exports = {
220220
use: [
221221
'babel-loader',
222222
{
223-
loader: 'svgr/lib/webpack',
223+
loader: 'svgr/webpack',
224224
options: {
225225
svgo: false,
226226
},

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@
6565
},
6666
"scripts": {
6767
"build": "rm -rf lib/ && NODE_ENV=production babel src -d lib",
68-
"ci": "yarn lint && yarn test",
68+
"ci": "yarn lint && yarn build && yarn test",
6969
"format": "prettier --write \"src/**/*.js\"",
7070
"lint": "eslint .",
7171
"release": "yarn build && standard-version && conventional-github-releaser",
7272
"clear": "rm -rf __fixtures_build__ lib",
73-
"test": "npm run clear && jest --runInBand --coverage && codecov",
73+
"test": "jest --runInBand --coverage && codecov",
7474
"prepublishOnly": "yarn run build"
7575
}
7676
}

src/webpack.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@ function svgrLoader(source) {
99
.catch(err => callback(err))
1010
}
1111

12-
export default svgrLoader
12+
function svgrLoaderWithWarning(source) {
13+
console.warn(
14+
'Using "svgr/lib/webpack" is deprecated and will be removed in v2. Please use "svgr/webpack" instead.',
15+
)
16+
return svgrLoader.call(this, source)
17+
}
18+
19+
export { svgrLoader }
20+
export default svgrLoaderWithWarning

src/webpack.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('webpack loader', () => {
3636
},
3737
},
3838
{
39-
loader: path.resolve(__dirname, 'webpack.js'),
39+
loader: path.resolve(__dirname, '../webpack.js'),
4040
options: {
4141
expandProps: false,
4242
},

webpack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* eslint-disable import/no-unresolved */
2-
module.exports = require('./lib/webpack')
2+
module.exports = require('./lib/webpack').svgrLoader

0 commit comments

Comments
 (0)