Commit bf71475d authored by Jure's avatar Jure

Merge branch 'refactor_webpack_plugins' into 'master'

chore: refactor webpack plugins

See merge request !49
parents 70b1c81f d0c41eff
Pipeline #9174 passed with stages
in 9 minutes and 7 seconds
const config = require('config')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = (opts = {}) => {
const plugins = []
if (opts.hmr) {
plugins.push(new webpack.HotModuleReplacementPlugin())
}
if (opts.html) {
plugins.push(
new HtmlWebpackPlugin({
title: 'PubSweet app',
template: '../app/index.ejs', // Load a custom template
inject: 'body', // Inject all scripts into the body
}),
)
}
if (opts.extractText) {
plugins.push(new ExtractTextPlugin('styles/main.css'))
}
if (opts.noEmitOnErrors) {
plugins.push(new webpack.NoEmitOnErrorsPlugin())
}
plugins.push(
new webpack.DefinePlugin({
'process.env.NODE_ENV': `"${opts.env}"`,
}),
)
// put dynamically required modules into the build
if (config.validations) {
plugins.push(
new webpack.ContextReplacementPlugin(/./, __dirname, {
[config.authsome.mode]: config.authsome.mode,
[config.validations]: config.validations,
}),
)
} else {
plugins.push(
new webpack.ContextReplacementPlugin(/./, __dirname, {
[config.authsome.mode]: config.authsome.mode,
}),
)
}
plugins.push(
new CopyWebpackPlugin([{ from: '../static' }]),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
)
return plugins
}
const path = require('path')
const webpack = require('webpack')
const ThemePlugin = require('pubsweet-theme-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const fs = require('fs-extra')
const config = require('config')
const { pick } = require('lodash')
......@@ -16,6 +13,8 @@ fs.ensureDirSync(outputPath)
const clientConfigPath = path.join(outputPath, 'client-config.json')
fs.writeJsonSync(clientConfigPath, clientConfig, { spaces: 2 })
const plugins = require('./plugins')
module.exports = [
{
// The configuration for the client
......@@ -48,26 +47,14 @@ module.exports = [
extensions: ['.js', '.jsx', '.json', '.scss'],
enforceExtension: false,
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"',
}),
// put dynamically required modules into the build
new webpack.ContextReplacementPlugin(/./, __dirname, {
[config.authsome.mode]: config.authsome.mode,
[config.validations]: config.validations,
}),
new CopyWebpackPlugin([{ from: '../static' }]),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
}),
],
plugins: plugins({
hmr: true,
html: false,
noEmitOnErrors: true,
extractText: false,
optimize: true,
env: 'development',
}),
node: {
fs: 'empty',
__dirname: true,
......
const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ThemePlugin = require('pubsweet-theme-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const fs = require('fs-extra')
const config = require('config')
const { pick } = require('lodash')
......@@ -18,6 +13,8 @@ fs.ensureDirSync(outputPath)
const clientConfigPath = path.join(outputPath, 'client-config.json')
fs.writeJsonSync(clientConfigPath, clientConfig, { spaces: 2 })
const plugins = require('./plugins')
module.exports = [
{
// The configuration for the client
......@@ -48,30 +45,13 @@ module.exports = [
extensions: ['.js', '.jsx', '.json', '.scss'],
plugins: [new ThemePlugin(config['pubsweet-client'].theme)],
},
plugins: [
new HtmlWebpackPlugin({
title: 'PubSweet app',
template: '../app/index.ejs', // Load a custom template
inject: 'body', // Inject all scripts into the body
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
// put dynamically required modules into the build
new webpack.ContextReplacementPlugin(/./, __dirname, {
[config.authsome.mode]: config.authsome.mode,
[config.validations]: config.validations,
}),
new ExtractTextPlugin('styles/main.css'),
new CopyWebpackPlugin([{ from: '../static' }]),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
}),
],
plugins: plugins({
hmr: false,
html: true,
extractText: true,
optimize: true,
env: 'production',
}),
node: {
fs: 'empty',
__dirname: true,
......
const path = require('path')
const webpack = require('webpack')
const ThemePlugin = require('pubsweet-theme-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const fs = require('fs-extra')
const config = require('config')
const { pick } = require('lodash')
......@@ -16,6 +13,8 @@ fs.ensureDirSync(outputPath)
const clientConfigPath = path.join(outputPath, 'client-config.json')
fs.writeJsonSync(clientConfigPath, clientConfig, { spaces: 2 })
const plugins = require('./plugins')
module.exports = [
{
// The configuration for the client
......@@ -47,28 +46,14 @@ module.exports = [
extensions: ['.js', '.jsx', '.json', '.scss'],
enforceExtension: false,
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"test"',
}),
// put dynamically required modules into the build
new webpack.ContextReplacementPlugin(/./, __dirname, {
[config.authsome.mode]: config.authsome.mode,
[config.validations]: config.validations,
}),
new CopyWebpackPlugin([{ from: '../static' }]),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
],
plugins: plugins({
hmr: true,
html: false,
noEmitOnErrors: true,
extractText: false,
optimize: true,
env: 'test',
}),
node: {
fs: 'empty',
__dirname: true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment