Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/frontend-config / webpack / webpack.dev.js
Size: Mime:
const { DefinePlugin, HotModuleReplacementPlugin } = require('webpack');

const { createRouter, getSchema } = require('./mockHelper');

/**
 * This is the webpack configuration used when running the frontend in development mode.
 * @param {WebpackAppParameters} parameters See {@link ../webpack.js}
 */
module.exports = async parameters => {
  const { publicPath, mocks } = parameters;

  const schema = mocks.swaggerJson ? await getSchema(mocks.swaggerJson) : null;

  return {
    mode: 'development',
    output: {
      filename: '[name].bundle.js',
      chunkFilename: '[name].bundle.js',
      publicPath: `/${publicPath}`,
    },
    /**
     * https://webpack.js.org/configuration/dev-server/
     */
    devServer: {
      open: true,
      openPage: publicPath,
      overlay: true,
      historyApiFallback: true,
      /**
       * Expose the mock endpoints
       */
      before: function injectMock(app) {
        if (schema !== null) {
          app.use(schema.basePath, createRouter(schema));
        }
      },
    },
    plugins: [
      /**
       * https://webpack.js.org/plugins/define-plugin/
       */
      new DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify('development'),
        'process.env.ASSETS_PATH': JSON.stringify(publicPath),
        'process.env.BUILD_TARGET': JSON.stringify(''),
      }),
      /**
       * https://webpack.js.org/plugins/hot-module-replacement-plugin
       */
      new HotModuleReplacementPlugin(),
    ],
  };
};