Webpack Encore:选择性或部分版本控制



我通常在Webpack中启用版本控制,但有没有更选择性的方法?

我需要保持一个或多个文件未经转换
如果我可以同时拥有这些文件的版本和未版本版本,那就更好了。

我当前的配置:

let Encore = require('@symfony/webpack-encore');
let UglifyJsPlugin = require('uglifyjs-webpack-plugin');
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.addEntry('app', './assets/js/app.js')
.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableSassLoader()
.autoProvidejQuery()
// I enable the versioning
.enableVersioning(Encore.isProduction())
// But i want an unversioned build of this file
.addStyleEntry('blog_article', './assets/css/blog_article.scss')
;
const config = Encore.getWebpackConfig();
if(Encore.isProduction()) {
config.plugins.push(new UglifyJsPlugin({
uglifyOptions: {
output: {
comments: false
}
}
}));
}
module.exports = [config];

电流输出:

  • app.XXX.js(版本(
  • blog_article.XXX.css(版本(

所需输出:

  • app.XXX.js(版本(
  • blog_article.XXX.css(版本(
  • blog_article.css(未转换(

一年过去了,这个问题可能已经解决了,但我也遇到了类似的问题。我需要在不添加哈希的情况下从资产中的特定目录复制文件。根据Symfony的webpack文档和webpack文件,这是我的解决方案。


if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
// directory where compiled assets will be stored
.setOutputPath('public_html/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
.addEntry('app', './assets/app.js')
.addLoader({
test: /.(png|woff|woff2|eot|ttf|svg)$/,
type: 'asset/resource',
})
.splitEntryChunks()
.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
// enables Sass/SCSS support
.enableSassLoader(function(options) {
// https://github.com/sass/node-sass#options
options.sassOptions = {outputStyle: 'compressed'}
})
.enablePostCssLoader()
// Copy files with hash
.copyFiles({
from: './assets/images',
to: 'images/[path][name].[hash:8].[ext]'
})
;
// build the second configuration
const mainConfig = Encore.getWebpackConfig();
// reset Encore to build the second config
Encore.reset();
Encore
.setOutputPath('public_html/build_editor/')
.setPublicPath('/build_editor')
.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(false)
// copy files without hash
.copyFiles({
from: './assets/editor_images',
to: 'images/[path][name].[ext]'
})
const editorAssetsConfig = Encore.getWebpackConfig();
editorAssetsConfig.name = 'editorAssetsConfig';
module.exports = [mainConfig, editorAssetsConfig];

最新更新