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

fix(index): revert to CJS exports #212

Merged
merged 1 commit into from
Sep 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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\";',
);
});
});