Webpack. Theming fallback -


is possible resolve theming path fallback webpack?

so let's have next structure:

    app/     ├── componenta/     │   └─ index.js     │     └── themes/         └── woot/             └── componenta/                 └── index.js 

and import

    import componenta 'app/componenta/index.js'; 

then depending on build want receive next:

  1. for webpackapp/componenta/index.js
  2. for theme="woot" webpackapp/themes/woot/componenta/index.js

thank you

it should that... didn't test, think represent starting point.

look @ normalmodulereplacementplugin

// webpack.config.js module.exports = env => {   const theme = env.theme || null;    const configs = object.create(null);    configs.plugins = [];    if(theme) {     const theming = new webpack.normalmodulereplacementplugin(     /(.*)components\/index/, (resource) => {          resource.request = resource           .request           .replace(/components\/index/, `components\/${theme}\/index`);       }   );      configs.plugins.push(theming);   }    return promise     .resolve(config)   ; }  // package.json {   "scripts": {     "webpack": "webpack --config webpack.config.js"   } }  // cli npm run webpack -- --env.theme=dark 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -