forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.ts
More file actions
32 lines (23 loc) · 1 KB
/
loader.ts
File metadata and controls
32 lines (23 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// @ts-ignore
import CSSBaseRaw from '!raw-loader!./client/css-base';
import { LoaderContext } from '../../../transpiled-module';
import getModules from './get-modules';
const CSSBasePath = '/node_modules/css-loader/css-base.js';
const getStyleId = id => id + '-css'; // eslint-disable-line
export default function transpile(
content: string,
loaderContext: LoaderContext
) {
loaderContext.emitModule(CSSBasePath, CSSBaseRaw, '/', false, false);
let result = '';
result += `exports = module.exports = require("${CSSBasePath}")(false);\n\n`;
if (loaderContext.options.modules) {
return getModules(content, loaderContext).then(({ css, exportTokens }) => {
result += `exports.push([module.id, ${JSON.stringify(css)}, ""])\n\n`;
result += `exports.locals = ${JSON.stringify(exportTokens)};`;
return Promise.resolve({ transpiledCode: result });
});
}
result += `exports.push([module.id, ${JSON.stringify(content)}, ""])`;
return Promise.resolve({ transpiledCode: result });
}