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

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

/* eslint-disable max-len, import/no-extraneous-dependencies */
2016-03-08 00:21:12 +03:00
import path from 'path';
import autoprefixer from 'autoprefixer';
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';
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';
import webpackIsomorphicToolsConfig
from './src/core/server/webpack-isomorphic-tools-config';
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] = `${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',
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',
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,
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'),
}),
// 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',
tests: path.resolve('./tests'),
2016-03-21 20:14:38 +03:00
},
2017-05-18 00:07:06 +03:00
modules: [
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;