2016-08-20 01:15:37 +03:00
|
|
|
/* eslint-disable max-len, no-console, import/no-extraneous-dependencies */
|
2016-03-08 00:21:12 +03:00
|
|
|
|
2016-03-23 19:25:07 +03:00
|
|
|
import fs from 'fs';
|
2016-03-08 00:21:12 +03:00
|
|
|
import path from 'path';
|
2016-08-20 01:15:37 +03:00
|
|
|
|
|
|
|
import config from 'config';
|
2016-03-08 00:21:12 +03:00
|
|
|
import webpack from 'webpack';
|
2016-08-20 01:15:37 +03:00
|
|
|
import WebpackIsomorphicToolsPlugin from 'webpack-isomorphic-tools/plugin';
|
2016-03-08 00:21:12 +03:00
|
|
|
|
2017-05-18 00:07:06 +03:00
|
|
|
import { getPlugins, getRules } from './webpack-common';
|
2016-04-28 00:06:27 +03:00
|
|
|
import webpackConfig from './webpack.prod.config.babel';
|
2016-08-20 01:15:37 +03:00
|
|
|
import webpackIsomorphicToolsConfig
|
|
|
|
from './src/core/server/webpack-isomorphic-tools-config';
|
2016-03-08 00:21:12 +03:00
|
|
|
|
2016-04-28 00:06:27 +03:00
|
|
|
const localDevelopment = config.util.getEnv('NODE_ENV') === 'development';
|
2016-03-22 01:11:54 +03:00
|
|
|
|
2016-03-08 00:21:12 +03:00
|
|
|
const webpackIsomorphicToolsPlugin =
|
|
|
|
new WebpackIsomorphicToolsPlugin(webpackIsomorphicToolsConfig);
|
2016-03-23 19:25:07 +03:00
|
|
|
|
|
|
|
const babelrc = fs.readFileSync('./.babelrc');
|
|
|
|
const babelrcObject = JSON.parse(babelrc);
|
|
|
|
|
|
|
|
const babelPlugins = babelrcObject.plugins || [];
|
|
|
|
const babelDevPlugins = [['react-transform', {
|
|
|
|
transforms: [{
|
|
|
|
transform: 'react-transform-hmr',
|
|
|
|
imports: ['react'],
|
|
|
|
locals: ['module'],
|
|
|
|
}],
|
|
|
|
}]];
|
|
|
|
|
|
|
|
const BABEL_QUERY = Object.assign({}, babelrcObject, {
|
2017-05-18 00:07:06 +03:00
|
|
|
plugins: localDevelopment ?
|
|
|
|
babelPlugins.concat(babelDevPlugins) : babelPlugins,
|
2016-03-23 19:25:07 +03:00
|
|
|
});
|
|
|
|
|
2016-03-08 00:21:12 +03:00
|
|
|
const webpackHost = config.get('webpackServerHost');
|
|
|
|
const webpackPort = config.get('webpackServerPort');
|
2016-04-28 00:06:27 +03:00
|
|
|
const assetsPath = path.resolve(__dirname, 'dist');
|
2016-03-08 00:21:12 +03:00
|
|
|
|
2016-05-27 20:36:39 +03:00
|
|
|
const hmr = `webpack-hot-middleware/client?path=//${webpackHost}:${webpackPort}/__webpack_hmr`;
|
2016-04-22 19:42:57 +03:00
|
|
|
|
2016-04-28 00:06:27 +03:00
|
|
|
const appName = config.get('appName');
|
|
|
|
const appsBuildList = appName ? [appName] : config.get('validAppNames');
|
2016-04-22 19:42:57 +03:00
|
|
|
|
|
|
|
const entryPoints = {};
|
2016-11-18 16:07:07 +03:00
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2016-04-22 19:42:57 +03:00
|
|
|
for (const app of appsBuildList) {
|
|
|
|
entryPoints[app] = [
|
|
|
|
hmr,
|
2017-05-23 00:02:23 +03:00
|
|
|
`${app}/client`,
|
2016-04-22 19:42:57 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-03-08 00:21:12 +03:00
|
|
|
export default Object.assign({}, webpackConfig, {
|
|
|
|
devtool: 'inline-source-map',
|
2017-05-18 00:07:06 +03:00
|
|
|
devServer: {
|
|
|
|
progress: true,
|
|
|
|
},
|
2016-04-28 00:06:27 +03:00
|
|
|
context: path.resolve(__dirname),
|
2016-04-22 19:42:57 +03:00
|
|
|
entry: entryPoints,
|
2016-03-08 00:21:12 +03:00
|
|
|
output: Object.assign({}, webpackConfig.output, {
|
|
|
|
path: assetsPath,
|
2016-04-22 19:42:57 +03:00
|
|
|
filename: '[name]-[hash].js',
|
|
|
|
chunkFilename: '[name]-[hash].js',
|
2016-05-27 20:36:39 +03:00
|
|
|
publicPath: `//${webpackHost}:${webpackPort}/`,
|
2016-03-08 00:21:12 +03:00
|
|
|
}),
|
|
|
|
module: {
|
2017-05-18 00:07:06 +03:00
|
|
|
rules: getRules({ babelQuery: BABEL_QUERY, bundleStylesWithJs: true }),
|
2016-03-08 00:21:12 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
2017-05-18 00:07:06 +03:00
|
|
|
...getPlugins(),
|
2016-03-08 00:21:12 +03:00
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
|
|
new webpack.IgnorePlugin(/webpack-stats\.json$/),
|
|
|
|
webpackIsomorphicToolsPlugin.development(),
|
|
|
|
],
|
|
|
|
});
|