* Adds a watcher for files in entryGlobals to properly recompile the project on changes.
(name, config, defsObj, callback)
| 47 | * Adds a watcher for files in entryGlobals to properly recompile the project on changes. |
| 48 | */ |
| 49 | function addWrapperWithGlobals(name, config, defsObj, callback) { |
| 50 | config.module.rules.push({ |
| 51 | test: new RegExp(`/${name}/.*?\\.js$`.replace(/\//g, /[/\\]/.source)), |
| 52 | use: [{ |
| 53 | loader: './scripts/fake-dep-loader.js', |
| 54 | options: { files: entryGlobals[name].map(entryPathToFilename) }, |
| 55 | }], |
| 56 | }); |
| 57 | const defsRe = new RegExp(`\\b(${ |
| 58 | Object.keys(defsObj) |
| 59 | .join('|') |
| 60 | .replace(/\./g, '\\.') |
| 61 | })\\b`, 'g'); |
| 62 | const reader = () => ( |
| 63 | entryGlobals[name] |
| 64 | .map(path => readGlobalsFile(path)) |
| 65 | .join('\n') |
| 66 | .replace(defsRe, s => defsObj[s]) |
| 67 | ); |
| 68 | const { header, footer, test } = callback(reader); |
| 69 | config.plugins.push( |
| 70 | new webpack.BannerPlugin({ test, raw: true, banner: header }), |
| 71 | new webpack.BannerPlugin({ test, raw: true, banner: footer, footer: true }) |
| 72 | ); |
| 73 | } |
| 74 | |
| 75 | function getCodeMirrorThemes() { |
| 76 | const name = 'neo.css'; |