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

78 строки
2.3 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 = {};
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,
`${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(),
2016-03-08 00:21:12 +03:00
new webpack.HotModuleReplacementPlugin(),
new webpack.IgnorePlugin(/webpack-stats\.json$/),
webpackIsomorphicToolsPlugin.development(),
],
});