Last active
January 25, 2022 21:18
-
-
Save ihorduchenko/895aaf215c2a84d1c252acfce13040e9 to your computer and use it in GitHub Desktop.
Disable Slate's Webpack javascript minification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const webpack = require('webpack'); | |
const merge = require('webpack-merge'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); | |
const SlateConfig = require('@shopify/slate-config'); | |
const SlateTagPlugin = require('@shopify/slate-tag-webpack-plugin'); | |
const babel = require('./parts/babel'); | |
const sass = require('./parts/sass'); | |
const entry = require('./parts/entry'); | |
const core = require('./parts/core'); | |
const css = require('./parts/css'); | |
const packageJson = require('../../../package.json'); | |
const getChunkName = require('../get-chunk-name'); | |
const getLayoutEntrypoints = require('./utilities/get-layout-entrypoints'); | |
const getTemplateEntrypoints = require('./utilities/get-template-entrypoints'); | |
const HtmlWebpackIncludeLiquidStylesPlugin = require('../html-webpack-include-chunks'); | |
const config = new SlateConfig(require('../../../slate-tools.schema')); | |
module.exports = merge([ | |
core, | |
entry, | |
babel, | |
sass, | |
css, | |
{ | |
mode: 'production', | |
devtool: 'hidden-source-map', | |
plugins: [ | |
new MiniCssExtractPlugin({ | |
filename: '[name].css.liquid', | |
}), | |
new webpack.DefinePlugin({ | |
'process.env': {NODE_ENV: '"production"'}, | |
}), | |
new UglifyJSPlugin({ | |
// sourceMap: true, | |
uglifyOptions: { | |
compress: false, | |
mangle: false, | |
output: { | |
beautify: false | |
} | |
} | |
}), | |
// generate dist/layout/*.liquid for all layout files with correct paths to assets | |
new HtmlWebpackPlugin({ | |
excludeChunks: ['static'], | |
filename: `../snippets/script-tags.liquid`, | |
template: path.resolve(__dirname, '../script-tags.html'), | |
inject: false, | |
minify: { | |
removeComments: true, | |
collapseWhitespace: true, | |
removeAttributeQuotes: false, | |
preserveLineBreaks: true, | |
// more options: | |
// https://github.com/kangax/html-minifier#options-quick-reference | |
}, | |
// necessary to consistently work with multiple chunks via CommonsChunkPlugin | |
chunksSortMode: 'dependency', | |
liquidTemplates: getTemplateEntrypoints(), | |
liquidLayouts: getLayoutEntrypoints(), | |
}), | |
new HtmlWebpackPlugin({ | |
filename: `../snippets/style-tags.liquid`, | |
template: path.resolve(__dirname, '../style-tags.html'), | |
inject: false, | |
minify: { | |
removeComments: true, | |
collapseWhitespace: true, | |
removeAttributeQuotes: false, | |
preserveLineBreaks: true, | |
// more options: | |
// https://github.com/kangax/html-minifier#options-quick-reference | |
}, | |
// necessary to consistently work with multiple chunks via CommonsChunkPlugin | |
chunksSortMode: 'dependency', | |
liquidTemplates: getTemplateEntrypoints(), | |
liquidLayouts: getLayoutEntrypoints(), | |
}), | |
new HtmlWebpackIncludeLiquidStylesPlugin(), | |
new SlateTagPlugin(packageJson.version), | |
], | |
optimization: { | |
splitChunks: { | |
chunks: 'initial', | |
name: getChunkName, | |
}, | |
minimizer: [ | |
// new UglifyJSPlugin({ | |
// uglifyOptions: { | |
// compress: false | |
// } | |
// }), | |
] | |
}, | |
}, | |
config.get('webpack.extend'), | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment