2016-08-20 01:15:37 +03:00
|
|
|
/* eslint-disable max-len, import/no-extraneous-dependencies */
|
2016-03-08 00:21:12 +03:00
|
|
|
import path from 'path';
|
|
|
|
|
2016-08-20 01:15:37 +03:00
|
|
|
import autoprefixer from 'autoprefixer';
|
2016-04-28 00:06:27 +03:00
|
|
|
import config from 'config';
|
2016-03-08 00:21:12 +03:00
|
|
|
import ExtractTextPlugin from 'extract-text-webpack-plugin';
|
2017-05-18 00:07:06 +03:00
|
|
|
import SriPlugin from 'webpack-subresource-integrity';
|
2016-08-20 01:15:37 +03:00
|
|
|
import webpack from 'webpack';
|
|
|
|
import WebpackIsomorphicToolsPlugin from 'webpack-isomorphic-tools/plugin';
|
2016-04-25 23:07:36 +03:00
|
|
|
|
2017-05-18 00:07:06 +03:00
|
|
|
import SriDataPlugin from './src/core/server/sriDataPlugin';
|
|
|
|
import { getPlugins, getRules } from './webpack-common';
|
2016-08-20 01:15:37 +03:00
|
|
|
import webpackIsomorphicToolsConfig
|
|
|
|
from './src/core/server/webpack-isomorphic-tools-config';
|
|
|
|
|
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) {
|
2017-05-23 00:02:23 +03:00
|
|
|
entryPoints[app] = `${app}/client`;
|
2016-04-22 19:42:57 +03:00
|
|
|
}
|
|
|
|
|
2016-06-28 21:44:25 +03:00
|
|
|
const settings = {
|
2016-03-08 00:21:12 +03:00
|
|
|
devtool: 'source-map',
|
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: {
|
2017-05-18 00:07:06 +03:00
|
|
|
crossOriginLoading: 'anonymous',
|
2016-04-28 00:06:27 +03:00
|
|
|
path: path.join(__dirname, 'dist'),
|
2016-04-22 19:42:57 +03:00
|
|
|
filename: '[name]-[chunkhash].js',
|
|
|
|
chunkFilename: '[name]-[chunkhash].js',
|
2016-05-27 16:28:19 +03:00
|
|
|
publicPath: config.has('staticHost') ? `${config.get('staticHost')}/` : '/',
|
2016-03-08 00:21:12 +03:00
|
|
|
},
|
|
|
|
module: {
|
2017-05-18 00:07:06 +03:00
|
|
|
rules: getRules(),
|
2016-03-08 00:21:12 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
2017-05-18 00:07:06 +03:00
|
|
|
...getPlugins(),
|
|
|
|
new ExtractTextPlugin({
|
|
|
|
filename: '[name]-[contenthash].css',
|
|
|
|
allChunks: true,
|
2016-04-25 23:07:36 +03:00
|
|
|
}),
|
2016-03-08 00:21:12 +03:00
|
|
|
// optimizations
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
2017-05-18 00:07:06 +03:00
|
|
|
sourceMap: true,
|
2017-03-29 18:33:41 +03:00
|
|
|
comments: false,
|
2016-03-08 00:21:12 +03:00
|
|
|
compress: {
|
2016-05-16 14:04:26 +03:00
|
|
|
drop_console: true,
|
2016-03-08 00:21:12 +03:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
new WebpackIsomorphicToolsPlugin(webpackIsomorphicToolsConfig),
|
2017-05-18 00:07:06 +03:00
|
|
|
new SriPlugin({ hashFuncNames: ['sha512'] }),
|
|
|
|
new SriDataPlugin({
|
|
|
|
saveAs: path.join(__dirname, 'dist', 'sri.json'),
|
|
|
|
}),
|
2017-01-09 14:51:01 +03:00
|
|
|
// This function helps ensure we do bail if a compilation error
|
|
|
|
// is encountered since --bail doesn't cause the build to fail with
|
|
|
|
// uglify errors.
|
|
|
|
// Remove when https://github.com/webpack/webpack/issues/2390 is fixed.
|
|
|
|
function bailOnStatsError() {
|
|
|
|
this.plugin('done', (stats) => {
|
|
|
|
if (stats.compilation.errors && stats.compilation.errors.length) {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(stats.compilation.errors);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2016-03-08 00:21:12 +03:00
|
|
|
],
|
|
|
|
resolve: {
|
2016-03-21 20:14:38 +03:00
|
|
|
alias: {
|
|
|
|
'normalize.css': 'normalize.css/normalize.css',
|
2017-05-23 00:02:23 +03:00
|
|
|
tests: path.resolve('./tests'),
|
2016-03-21 20:14:38 +03:00
|
|
|
},
|
2017-05-18 00:07:06 +03:00
|
|
|
modules: [
|
2016-12-22 07:10:26 +03:00
|
|
|
path.resolve('./src'),
|
2017-05-18 00:07:06 +03:00
|
|
|
'node_modules',
|
2016-03-08 00:21:12 +03:00
|
|
|
],
|
2017-05-18 00:07:06 +03:00
|
|
|
extensions: ['.js', '.jsx'],
|
2016-03-08 00:21:12 +03:00
|
|
|
},
|
|
|
|
};
|
2016-06-28 21:44:25 +03:00
|
|
|
|
|
|
|
if (config.get('enablePostCssLoader')) {
|
2017-05-18 00:07:06 +03:00
|
|
|
settings.plugins.push(
|
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
options: {
|
|
|
|
context: path.resolve(__dirname),
|
|
|
|
postcss: [
|
|
|
|
autoprefixer({ browsers: ['last 2 versions'] }),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
2016-06-28 21:44:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default settings;
|