From 7d65b8bda4e31b29b1c18d9cff1ae004140e5038 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 29 Oct 2019 13:35:47 -0500 Subject: [PATCH] chore(sass): relocate chokidar removal --- rollup.config.js | 13 ------------- rollup.plugin.sass.js | 21 ++++++++++++++++++--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index b35523f..31020f2 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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: [ diff --git a/rollup.plugin.sass.js b/rollup.plugin.sass.js index 9f7b324..e3934d5 100644 --- a/rollup.plugin.sass.js +++ b/rollup.plugin.sass.js @@ -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 }