Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
fix(index): revert to CJS exports (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky authored and joshwiens committed Sep 30, 2017
1 parent c49aceb commit f412b3e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
18 changes: 9 additions & 9 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,39 @@ 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";',
);
});
});

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\";',
);
});
});
Expand All @@ -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\";',
);
});

Expand All @@ -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\";',
);
});
});

0 comments on commit f412b3e

Please sign in to comment.