Skip to content

[Dev Server] CSS and JS files are not found anymore #941

Closed
@aarongerig

Description

@aarongerig

I recently switched to @symfony/webpack-encore:^1.0. Unfortunately my webpack-dev-server functionality isn't working as expected anymore. Maybe it's due to wrong configuration, although I didn't change it (it worked in previous versions, e.g. v0.33).

Here's my current configuration:

const { resolve } = require('path');
const Encore = require('@symfony/webpack-encore');
const StyleLintPlugin = require('stylelint-webpack-plugin');

const paths = {
  output: resolve(__dirname, './web/build/'),
  pattern: /\.(jpe?g|png|gif|svg|webp)$/i,
  public: 'build',
  source: resolve(__dirname, './assets'),
  vendor: resolve(__dirname, './node_modules'),
};

Encore
  // Set output and public paths
  .setOutputPath(`${paths.output}/`)
  .setPublicPath(`/${paths.public}`)

  // Clean output before build
  .cleanupOutputBeforeBuild()

  // JavaScript
  .addEntry('js/app', `${paths.source}/js/app.js`)
  .enableSingleRuntimeChunk()
  .enableEslintLoader()
  .splitEntryChunks()
  .configureBabel(() => {}, {
    useBuiltIns: 'usage',
    corejs: 3,
  })

  // CSS
  .addStyleEntry('css/global', `${paths.source}/scss/global.scss`)
  .addStyleEntry('css/email', `${paths.source}/scss/email.scss`)
  .addStyleEntry('css/editmode', `${paths.source}/scss/editmode.scss`)
  .enableSassLoader(() => {}, { resolveUrlLoader: false })
  .enablePostCssLoader()
  .addPlugin(new StyleLintPlugin())

  // Copy images
  .copyFiles({
    from: `${paths.source}/images`,
    pattern: paths.pattern,
    to: 'images/[path][name].[hash:8].[ext]',
  })

  // Source maps and cache buster
  .enableSourceMaps(!Encore.isProduction())
  .enableVersioning(Encore.isProduction())

  // Advanced config options
  .configureWatchOptions((options) => {
    options.poll = true;
    options.ignored = `${paths.vendor}/`;
  })
  .configureLoaderRule('images', (rule) => {
    rule.exclude = [
      `${paths.source}/custom/icons`,
    ];
  })
  .addRule({
    test: /\.svg$/,
    include: [
      `${paths.source}/custom/icons`,
    ],
    loader: 'raw-loader',
  });

// Advanced webpack config
const config = Encore.getWebpackConfig();
config.optimization.concatenateModules = true;

module.exports = config;

Very important to notice: With the .bin/encore dev command it works properly (I'm loading my files via the Webpack Encore Bundle => Symfony). With the .bin/encore dev-server --host localhost --port 2000 I get following errors in my console:

webpack-encore-dev-server

Is there anything I'm missing or doing wrong? Thanks for any feedback!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions