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

问题描述 投票:0回答:1

我通常在 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-encore
1个回答
0
投票

一年过去了,问题应该解决了,但我也有类似的问题。我需要从资产中的特定目录复制文件而不添加哈希。根据Symfony webpack docsWebpack docs,这是我的解决方案。


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];

© www.soinside.com 2019 - 2024. All rights reserved.