Skip to content

Commit

Permalink
chore(sass): relocate chokidar removal
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Oct 29, 2019
1 parent 7260896 commit 7d65b8b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
13 changes: 0 additions & 13 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@ export default {
rollupResolve({
preferBuiltins: true
}),
{
generateBundle(_options, bundle) {
// chokidar is required by sass.dart
// however this build doesn't use or need chokidar
// so we're manually hacking the source to remove it
Object.keys(bundle).forEach(fileName => {
bundle[fileName].code = bundle[fileName].code.replace(
'require("chokidar")',
'{}'
);
});
}
},
],

external: [
Expand Down
21 changes: 18 additions & 3 deletions rollup.plugin.sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,29 @@ const render = Sass.render;
export { render };
`;

if (code.indexOf('dartNodePreambleSelf.window') === -1) {
if (!code.includes('dartNodePreambleSelf.window')) {
// in jest environments, global.window DOES exist
// which messes with sass's file path resolving on node
// remove global.window check to force it to know we're on node
throw new Error('cannot find "dartNodePreambleSelf.window" in sass.dart');
}
code = code.replace(
'dartNodePreambleSelf.window',
'false /** NODE ENVIRONMENT **/'
);

if (!code.includes('require("chokidar")')) {
// chokidar is required by sass.dart
// however this build doesn't use or need chokidar
// so we're manually remove it from the source
throw new Error('cannot find "require("chokidar")" in sass.dart');
}
code = code.replace(
'require("chokidar")',
'{}'
);

code = minify(code, { module: true }).code;

code = code.replace('dartNodePreambleSelf.window', 'false /** NODE ENVIRONMENT **/');
code = minify(code, {module: true}).code;
return code
}

0 comments on commit 7d65b8b

Please sign in to comment.