From f412b3e9f4c33f83bbc4fb25b2f9e902cc0dff19 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Sun, 1 Oct 2017 00:53:00 +0200 Subject: [PATCH] fix(index): revert to CJS exports (#212) --- src/index.js | 4 ++-- test/loader.test.js | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/index.js b/src/index.js index 3ddef31..9cc8ef6 100644 --- a/src/index.js +++ b/src/index.js @@ -65,8 +65,8 @@ export default function loader(content) { if (options.emitFile === undefined || options.emitFile) { this.emitFile(outputPath, content); } - - return `export default ${publicPath};`; + // TODO revert to ES2015 Module export, when new CSS Pipeline is in place + return `module.exports = ${publicPath};`; } export const raw = true; diff --git a/test/loader.test.js b/test/loader.test.js index 2ee2285..23eea9a 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -90,19 +90,19 @@ describe('correct-filename', () => { describe('publicPath option', () => { it('should be supported', () => { expect(run('/file.txt', 'publicPath=http://cdn/').result).toEqual( - 'export default "http://cdn/81dc9bdb52d04dc20036dbd8313ed055.txt";', + 'module.exports = "http://cdn/81dc9bdb52d04dc20036dbd8313ed055.txt";', ); }); it('should override public path when given empty string', () => { expect(run('/file.txt', 'publicPath=').result).toEqual( - 'export default "81dc9bdb52d04dc20036dbd8313ed055.txt";', + 'module.exports = "81dc9bdb52d04dc20036dbd8313ed055.txt";', ); }); it('should use webpack public path when not set', () => { expect(run('/file.txt').result).toEqual( - 'export default __webpack_public_path__ + "81dc9bdb52d04dc20036dbd8313ed055.txt";', + 'module.exports = __webpack_public_path__ + "81dc9bdb52d04dc20036dbd8313ed055.txt";', ); }); }); @@ -110,19 +110,19 @@ describe('publicPath option', () => { describe('useRelativePath option', () => { it('should be supported', () => { expect(run('/this/is/the/context/file.txt', 'useRelativePath=true').result).toEqual( - 'export default __webpack_public_path__ + \"./81dc9bdb52d04dc20036dbd8313ed055.txt\";', + 'module.exports = __webpack_public_path__ + \"./81dc9bdb52d04dc20036dbd8313ed055.txt\";', ); expect(run('/this/is/file.txt', 'useRelativePath=true').result).toEqual( - 'export default __webpack_public_path__ + \"../../81dc9bdb52d04dc20036dbd8313ed055.txt\";', + 'module.exports = __webpack_public_path__ + \"../../81dc9bdb52d04dc20036dbd8313ed055.txt\";', ); expect(run('/this/file.txt', 'context=/this/is/the/&useRelativePath=true').result).toEqual( - 'export default __webpack_public_path__ + \"../../81dc9bdb52d04dc20036dbd8313ed055.txt\";', + 'module.exports = __webpack_public_path__ + \"../../81dc9bdb52d04dc20036dbd8313ed055.txt\";', ); expect(run('/this/file.txt', 'context=/&useRelativePath=true').result).toEqual( - 'export default __webpack_public_path__ + \"this/81dc9bdb52d04dc20036dbd8313ed055.txt\";', + 'module.exports = __webpack_public_path__ + \"this/81dc9bdb52d04dc20036dbd8313ed055.txt\";', ); }); }); @@ -134,7 +134,7 @@ describe('outputPath function', () => { expect(runWithOptions('/this/is/the/context/file.txt', options).result) .toEqual( - 'export default __webpack_public_path__ + \"/path/set/by/func\";', + 'module.exports = __webpack_public_path__ + \"/path/set/by/func\";', ); }); @@ -145,7 +145,7 @@ describe('outputPath function', () => { expect(runWithOptions('/this/is/the/context/file.txt', options).result) .toEqual( - 'export default __webpack_public_path__ + \"./81dc9bdb52d04dc20036dbd8313ed055.txt\";', + 'module.exports = __webpack_public_path__ + \"./81dc9bdb52d04dc20036dbd8313ed055.txt\";', ); }); });