Skip to content

Commit

Permalink
Update JS dependency copy-webpack-plugin to v6 (pymedusa#8094)
Browse files Browse the repository at this point in the history
* Update JS dependency copy-webpack-plugin to v6

* bump travis node version to 12.

* Fix webpack.config.js for breaking changes in copy-webpack-plugin
* Still a bug that minimizes all static assets css files.

* Moved OptimizeCssAssetsPlugin to optimization (as per wepack 4.x recommendation)

* Fix copy ignore

* Only minimize CSS on production builds

Restore plugin instead of minimizer

* Try it the other way

* Normalize CRLF->LF using sed

Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: P0psicles <[email protected]>
Co-authored-by: sharkykh <[email protected]>
  • Loading branch information
4 people authored May 24, 2020
1 parent d34d726 commit 9b96532
Show file tree
Hide file tree
Showing 7 changed files with 1,770 additions and 120 deletions.
6 changes: 6 additions & 0 deletions .github/build-themes-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ size_before=$(get_size $path_to_built_themes)
[[ -n $build_cmd ]] && run_verbose "$build_cmd"
run_verbose "yarn gulp sync"

# Normalize line endings in changed files
changed_files=$(git status --porcelain -- $path_to_built_themes | sed s/^...//)
for file in $changed_files; do
sed -i 's/\r$//g' ../../$file;
done

# Keep track of the new themes size.
size_after=$(get_size $path_to_built_themes)

Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ script: false

# Use of YAML aliases inspired by https://link.medium.com/vUG5hZ9oW3
# There's no support for concatenation so we must do this
_node_version: &_node_version '10.16.0'
_nvm_install: &_nvm_install nvm install v10.16.0
_node_version: &_node_version '12.13.0'
_nvm_install: &_nvm_install nvm install v12.13.0
_install_yarn_bin: &_install_yarn_bin >-
curl -o- -L https://yarnpkg.com/install.sh | bash &&
export PATH="$HOME/.yarn/bin:$PATH"
Expand Down
2 changes: 1 addition & 1 deletion themes-default/slim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"browser-env": "3.3.0",
"clean-webpack-plugin": "3.0.0",
"codecov": "3.7.0",
"copy-webpack-plugin": "5.1.1",
"copy-webpack-plugin": "6.0.1",
"cross-env": "7.0.2",
"css-loader": "3.5.3",
"eslint": "7.1.0",
Expand Down
96 changes: 54 additions & 42 deletions themes-default/slim/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const FileManagerPlugin = require('filemanager-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');

const pkg = require('./package.json');

Expand Down Expand Up @@ -114,6 +115,14 @@ const webpackConfig = (env, mode) => ({
runtimeChunk: {
name: 'vendors'
},
minimizer: [
// Minify js files:
// (TerserJS is webpack default minifier but we have to specify it explicitly
// as soon as we include more minifiers)
new TerserJSPlugin({}),
// Minify css files:
new OptimizeCssAssetsPlugin({})
],
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
Expand Down Expand Up @@ -213,7 +222,6 @@ const webpackConfig = (env, mode) => ({
jQuery: 'jquery'
}),
new VueLoaderPlugin(),
new OptimizeCssAssetsPlugin({}),
new MiniCssExtractPlugin({
filename: 'css/[name].css'
}),
Expand All @@ -230,47 +238,51 @@ const webpackConfig = (env, mode) => ({
}),
// Copy static files for each theme
// Don't use for assets emitted by Webpack because this plugin runs before the bundle is created.
new CopyWebpackPlugin([
// Templates
...perTheme(theme => ({
context: './views/',
from: '**',
to: path.resolve(theme.dest, 'templates')
})),
// Create package.json
...perTheme(theme => ({
from: 'package.json',
to: path.resolve(theme.dest, 'package.json'),
toType: 'file',
transform: content => theme.makeMetadata(content)
})),
// Root files: index.html
...perTheme(theme => ({
from: 'index.html',
to: path.resolve(theme.dest),
toType: 'dir'
})),
// Old JS files
...perTheme(theme => ({
context: './static/',
from: 'js/**',
to: path.resolve(theme.dest, 'assets')
})),
// Old CSS files
...perTheme(theme => ({
context: './static/',
from: 'css/**',
// Ignore theme-specific files as they are handled by the next entry
ignore: cssThemes.map(theme => `css/${theme.css}`),
to: path.resolve(theme.dest, 'assets')
})),
// Old CSS files - themed.css
...perTheme(theme => ({
from: `static/css/${theme.css}`,
to: path.resolve(theme.dest, 'assets', 'css', 'themed.css'),
toType: 'file'
}))
])
new CopyWebpackPlugin({
patterns: [
// Templates
...perTheme(theme => ({
context: './views/',
from: '**',
to: path.resolve(theme.dest, 'templates')
})),
// Create package.json
...perTheme(theme => ({
from: 'package.json',
to: path.resolve(theme.dest, 'package.json'),
toType: 'file',
transform: content => theme.makeMetadata(content)
})),
// Root files: index.html
...perTheme(theme => ({
from: 'index.html',
to: path.resolve(theme.dest),
toType: 'dir'
})),
// Old JS files
...perTheme(theme => ({
context: './static/',
from: 'js/**',
to: path.resolve(theme.dest, 'assets')
})),
// Old CSS files
...perTheme(theme => ({
context: './static/',
from: 'css/**',
to: path.resolve(theme.dest, 'assets'),
globOptions: {
// Ignore theme-specific files as they are handled by the next entry
ignore: cssThemes.map(theme => `**/css/${theme.css}`)
}
})),
// Old CSS files - themed.css
...perTheme(theme => ({
from: `static/css/${theme.css}`,
to: path.resolve(theme.dest, 'assets', 'css', 'themed.css'),
toType: 'file'
}))
]
})
]
});

Expand Down
Loading

0 comments on commit 9b96532

Please sign in to comment.