webpack.config.prod.js 1.83 KB
const webpack = require('webpack');
const paths = require('./paths');
const nodeExternals = require('webpack-node-externals');
const CopyWebpackPlugin = require('copy-webpack-plugin')

module.exports = {
  target: 'node',
  entry: paths.appEntry,
  output: {
    path: paths.appBuild,
    filename: 'index.js'
  },
  externals: [nodeExternals()],
  resolve: {
    modules: [paths.appLib, paths.appSrc, paths.appNodeModules],
    extensions: [
      '.mjs',
      '.web.ts',
      '.ts',
      '.web.tsx',
      '.tsx',
      '.web.js',
      '.js',
      '.json',
      '.web.jsx',
      '.jsx',
    ],
  },
  module: {
    strictExportPresence: true,
    rules: [
      {
        oneOf: [
          {
            test: /\.(js|jsx|mjs)$/,
            loader: require.resolve('babel-loader'),
            options: {
              cacheDirectory: true,
            },
          },
          {
            test: /\.(ts|tsx)$/,
            include: paths.appSrc,
            use: [
              {
                loader: require.resolve('ts-loader'),
                options: {
                  transpileOnly: true,
                },
              },
            ],
          },
          {
            test: /\.(graphql|gql)$/,
            loader: require.resolve('graphql-tag/loader'),
          }
        ],
      },
    ],
  },
  plugins: [
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': '"production"',
      '__DEV__': false
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false,
        comparisons: false,
      },
      mangle: {
        safari10: true,
      },
      output: {
        comments: false,
        ascii_only: true,
      },
    }),
    new CopyWebpackPlugin([
      { from: paths.serverAssets, to: 'assets' },
    ])
  ],
  devtool: 'sourcemap'
};