0.1.0 • Published 7 years ago

cross-loader v0.1.0

Weekly downloads
8
License
CC0-1.0
Repository
github
Last release
7 years ago

cross-loader

Load generated webpack modules from another build as if they were your own.

build status coverage license version downloads

npm install cross-loader

You need consistent module ids between the client and server for this to do what it needs to. This means either using HashedModuleIdsPlugin or using NamedModulesPlugin both of which are consistent.

The client build has things which generate modules you would like to reference on the server – e.g. URLs to images.

var webpack = require('webpack');

module.exports = {
  modules: {
    loaders: [{
      test: /\.(jpg|png)$/,
      loader: 'file-loader',
    }]
  },
  plugins: [
    new webpack.HashedModuleIdsPlugin(),
    new StatsPlugin('stats.json')
  ]
}

On the server you can use cross-loader to automatically bring in those modules for you assuming your stats were generated with modules: true and source: true.

var path = require('path');

module.exports = {
  modules: {
    loaders: [{
      test: /\.(jpg|png)$/,
      loader: 'cross-loader',
      query: JSON.stringify({
        stats: path.join('./' 'dist', 'stats.json'),
      }),
    }]
  },
  plugins: [
    new webpack.HashedModuleIdsPlugin()
  ]
}