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:
- for
webpack
→app/componenta/index.js
- for
theme="woot" webpack
→app/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
Post a Comment