Skip to content
Open
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 index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = function(content, ...rest) {
const { failed, success } = makeDoneHandlers(this.async(), content, rest);

const filename = this.resourcePath;
const { mode = 'emit' } = loaderUtils.getOptions(this) || {};
const { mode = 'emit', banner = bannerMessage } = loaderUtils.getOptions(this) || {};
if (!validModes.includes(mode)) {
return failed(new Error(`Invalid mode option: ${mode}`));
}
Expand All @@ -96,7 +96,7 @@ module.exports = function(content, ...rest) {
}
}

const cssModuleDefinition = `${bannerMessage}\n${cssModuleToInterface(cssModuleKeys)}\n${cssModuleExport}`;
const cssModuleDefinition = `${banner}\n${cssModuleToInterface(cssModuleKeys)}\n${cssModuleExport}`;

if (mode === 'verify') {
read((err, fileContents) => {
Expand Down
1 change: 1 addition & 0 deletions test/banner-custom/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.css.d.ts
11 changes: 11 additions & 0 deletions test/banner-custom/__snapshots__/banner-custom.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Can add custom banners 1`] = `
"// @generated
interface CssExports {
'foo': string;
}
export const cssExports: CssExports;
export default cssExports;
"
`;
15 changes: 15 additions & 0 deletions test/banner-custom/banner-custom.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fs = require('fs');
const compiler = require('../compiler.js');

test('Can add custom banners', async () => {
await compiler(require.resolve('./index.js'), {
banner: "// @generated",
});

const declaration = fs.readFileSync(
require.resolve('./index.css.d.ts'),
'utf-8'
);

expect(declaration).toMatchSnapshot();
});
3 changes: 3 additions & 0 deletions test/banner-custom/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
display: block;
}
1 change: 1 addition & 0 deletions test/banner-custom/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import styles from './index.css';