diff --git a/index.js b/index.js index ea4f387..8c3ab72 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,12 @@ +const jsesc = require('jsesc'); + module.exports = function (source) { if (this.cacheable) this.cacheable(); var value = typeof source === "string" ? JSON.parse(source) : source; - value = JSON.stringify(value) - .replace(/\u2028/g, '\\u2028') - .replace(/\u2029/g, '\\u2029'); + value = JSON.stringify(value); + value = jsesc(value); return `module.exports = ${value}`; } diff --git a/package-lock.json b/package-lock.json index c65b48d..a4f2075 100644 --- a/package-lock.json +++ b/package-lock.json @@ -760,6 +760,11 @@ "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, + "jsesc": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.1.tgz", + "integrity": "sha1-5CGiqOINawgZ3yiQj3glJrlt0f4=" + }, "json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", diff --git a/package.json b/package.json index 2bdad48..e53c420 100644 --- a/package.json +++ b/package.json @@ -13,5 +13,8 @@ "repository": { "type": "git", "url": "https://github.com/webpack/json-loader.git" + }, + "dependencies": { + "jsesc": "^2.5.1" } }