addons-frontend/webpack.dev.config.babel.js

88 строки
2.7 KiB
JavaScript
Исходник Обычный вид История

/* 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';
import config from 'config';
2016-03-08 00:21:12 +03:00
import webpack from 'webpack';
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';
import webpackConfig from './webpack.prod.config.babel';
import webpackIsomorphicToolsConfig
from './src/core/server/webpack-isomorphic-tools-config';
2016-03-08 00:21:12 +03:00
const localDevelopment = config.util.getEnv('NODE_ENV') === 'development';
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');
const assetsPath = path.resolve(__dirname, 'dist');
2016-03-08 00:21:12 +03:00
const hmr = `webpack-hot-middleware/client?path=//${webpackHost}:${webpackPort}/__webpack_hmr`;
2016-04-22 19:42:57 +03:00
const appName = config.get('appName');
const appsBuildList = appName ? [appName] : config.get('validAppNames');
2016-04-22 19:42:57 +03:00
const entryPoints = {};
for (const app of appsBuildList) {
entryPoints[app] = [
hmr,
`${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,
},
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',
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(),
// Load unminified React and Redux in development to get better
// error messages, because they use
// [Invariant](https://github.com/zertosh/invariant) which
// hides error messages in the production build.
new webpack.NormalModuleReplacementPlugin(
2017-11-23 16:52:10 +03:00
/^react$/, 'react/umd/react.development.js'),
new webpack.NormalModuleReplacementPlugin(
2017-11-23 16:52:10 +03:00
/^react-dom$/, 'react-dom/umd/react-dom.development.js'),
new webpack.NormalModuleReplacementPlugin(
/^redux$/, 'redux/dist/redux.js'),
2016-03-08 00:21:12 +03:00
new webpack.HotModuleReplacementPlugin(),
new webpack.IgnorePlugin(/webpack-stats\.json$/),
webpackIsomorphicToolsPlugin.development(),
],
});