brewster
brewster

Reputation: 4492

can i write files with write-file-webpack-plugin without a server?

i have 2 webpack configurations... 1 uses express to serve assets, but the other is used via command line. using the same configuration for the write-file-webpack-plugin, the express server writes the bundles as expected, but the cli config does not. i noticed in the write-file-webpack-plugin docs, there is a simple dev server setup, so will the plugin only write the files when they are served/requested somehow? i expected by just running webpack with the configuration with the write-plugin initialized, the files would be written to the file system immediately.

webpack.config.js

var Write, glob, path;
glob = require('webpack-glob-entry');
path = require('path');
Write = require('write-file-webpack-plugin');

module.exports = function(config, args) {
  return {
    mode: 'none',
    entry: glob(path.join(config.rootPath, 'user', 'libs', '**', '*_test.js')),
    output: {
      filename: '[name].js',
      path: path.join(config.rootPath, '.tmp')
    },
    plugins: [new Write()],
    module: {
      rules: [
        {
          test: /\.js$/,
          use: [
            {
              loader: 'babel-loader'
            }
          ]
        }
      ]
    }
  };
};

Upvotes: 1

Views: 716

Answers (1)

brewster
brewster

Reputation: 4492

i finally discovered that after i load the configuration, there is a run method that i needed to call on the compiler. webpack({config}).run()

Upvotes: 1

Related Questions