Skip to content

support ideas

edeustace edited this page Jul 18, 2017 · 1 revision

try a runtime config option for support modules.

A rough dump of an idea of setting up runtime support mechanism, allow the processors to fold over an input config to produce the final config to send to webpack.

// my-custom-config-processor

/**
 * 
 * @param moduleIds an array of modules that depends on this runtime support module. 
 * @param config the webpack config object
 */
export interface Options {
  /**
   * does this processor apply globally?
   */
  readonly global: boolean;
  /**
   * if not global which module ids does it apply to?
   */
  readonly moduleIds: string[];
}

export default function (opts: Options, config: webpack.Configuration) {

  const existingRule = config.rules.find((r: any) => {
    return r.test === 'my-custom-test';
  });

  if (!existingRule) {
    const newRule = {
      test: 'my-custom-test',
      use: [

      ]
    };
    config.rules.push(newRule);
  }
  const existingFn = config.plugins.postcss || (() => []);

  config.plugins.postcss = () => {
    const arr = existingFn();
    return arr.concat([/*???*/]);
  };

  return config;
}
//item.webpack.config.js

//add all the custom processor as runtime dependencies...
const processor = require('my-custom-config-processor');

const baseConfig = {/* the basic config created by pie-cli */ };

const processors = [processor, /*...*/];

const config = processors.reduce((acc, p) => p(acc), baseConfig);
module.exports = config;
Clone this wiki locally