首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Webpack·恩科删除我的照片

Webpack·恩科删除我的照片
EN

Stack Overflow用户
提问于 2018-07-17 09:48:29
回答 1查看 766关注 0票数 0

我面临着Webpack,Encore和SCSS的问题。

我在我的项目中有一个SCSS文件,一个图片,和Webpack Encore。但是当我和Webpack一起编译的时候,它会生成我的原始文件logo.pnglogo.<hash>.png中的一个拷贝,正常的,但是图像没有显示,我甚至不能打开它,图像被删除了。

另一方面,我用CopyWebpackPlugin生成的所有图像都是可读的,但我无法从我的SCSS访问它.

结构

代码语言:javascript
复制
/assets
    /images
        logo.png
    /scss
        app.scss
/public
    /build
        /css
            app.<hash>.css
        /images
            logo.<hash>.png

app.scss

代码语言:javascript
复制
div {
    background-image: url('../images/logo.png');
}

webpack.config.js

代码语言:javascript
复制
var Encore = require('@symfony/webpack-encore');
var webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');

Encore
    // the project directory where compiled assets will be stored
    .setOutputPath('public/build/')

    // the public path used by the web server to access the previous directory
    .setPublicPath('/build')

    .cleanupOutputBeforeBuild()

    .enableSourceMaps(!Encore.isProduction())

    // uncomment to create hashed filenames (e.g. app.abc123.css)
    .enableVersioning()

    // IMAGES
    .addPlugin(new CopyWebpackPlugin([
        {
            from: './assets/images',
            to: 'images',
            force: true
        }
    ]))

    // CSS
    .addStyleEntry('css/app', [
        './assets/scss/app.scss',
    ])

    // uncomment if you use Sass/SCSS files
    .enableSassLoader(function(options) {
        // https://github.com/sass/node-sass#options
    })

    .addLoader({loader: 'shebang-loader'})

    // uncomment for legacy applications that require $/jQuery as a global variable
    .autoProvidejQuery()

    .enableBuildNotifications()
;

module.exports = Encore.getWebpackConfig();

有人能告诉我我做错了什么吗

EN

回答 1

Stack Overflow用户

发布于 2019-01-10 12:45:01

你可以移除

.cleanupOutputBeforeBuild()

或者添加这样的东西:

代码语言:javascript
复制
.cleanupOutputBeforeBuild(['static'], (options) => {
        options.verbose = true;
        options.root = __dirname;
        options.exclude = ['img'];
    })
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51378238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档