Webpack is failing to recognize certain CSS files

My development stack includes Vue.js 2.5.15, Webpack 4.12.0, css-loader 0.28.11, ASP.Net Core 2.1 in Visual Studio 2017.

Starting with the Visual Studio asp.net core template project for Vue and Typescript, I prefer to have individual small CSS files within each component folder under ClientApp. This way, all .vue, .ts, and .css files are located together.

However, I encountered a situation where only some of the CSS files were included in Main.js when running the app. I am trying to figure out why some CSS files in these subfolders are included while others are not, even though they are referenced in the same way. Here are more details about my setup:

Folder structure: Component Folder Structure Example

NPM packages: NPM Packages

webpack.config.js:

const path = require('path');
const webpack = require('webpack');
const VueLoader = require('vue-loader');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const bundleOutputDir = './wwwroot/dist';

module.exports = (env) => {
    const isDevBuild = !(env && env.prod);

    return [{
        stats: { modules: false },
        context: __dirname,
        entry: { 'main': './ClientApp/boot.ts' },
        mode: "development",
        module: {
            rules: [
                { test: /\.vue$/, include: /ClientApp/, loader: 'vue-loader', options: { loaders: { js: 'ts-loader' } } },
                { test: /\.ts$/, include: /ClientApp/, use: 'ts-loader' },
                { test: /\.css$/, use: isDevBuild ? [ 'style-loader', 'css-loader' ] : ExtractTextPlugin.extract({ use: 'css-loader?minimize' }) },
                { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
            ]
        },
        resolve: {
            extensions: ['.js', '.ts'],
            alias: {
                'vue$': 'vue/dist/vue.esm.js'
            }
        },
        output: {
            path: path.join(__dirname, bundleOutputDir),
            filename: '[name].js',
            publicPath: 'dist/'
        },
        plugins: [
            new VueLoader.VueLoaderPlugin(),
            new webpack.DefinePlugin({
                'process.env': {
                    NODE_ENV: JSON.stringify(isDevBuild ? 'development' : 'production')
                }
            }),
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./wwwroot/dist/vendor-manifest.json')
            })
        ].concat(isDevBuild ? [
            // Plugins that apply in development builds only
            new webpack.SourceMapDevToolPlugin({
                filename: '[file].map', 
                moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') 
            })
        ] : [
            // Plugins that apply in production builds only
            new webpack.optimize.UglifyJsPlugin(),
            new ExtractTextPlugin('site.css')
        ])
    }];
};

The generated main.js file in my dist folder includes the CSS for 'settings' but not for 'monkeys'. I'm wondering why this inconsistency exists?

Monkeys.vue:

<template>
    <div id="monkeys-container">
        I love monkeys!!!!!!!!
    </div>
</template>

<style src="./monkeys.css"></style>
<script src="./monkeys.ts"></script>
<!--<style>
    @import './monkeys.css';
</style>-->

In settings.vue:

<template>
    <div id="settings-container">
        <grid v-if="settingsloaded" v-bind:headernames="headernames" v-bind:coltypes="coltypes" v-bind:datarows="datarows"></grid>
        <div v-else>{{ message }}</div>
    </div>
</template>

<style src="./settings.css"></style>
<script src="./settings.ts"></script>

I would appreciate any insights on why webpack is behaving inconsistently in including CSS files without adding any additional npm packages. Although I can use import statements in boot.ts to manually add each CSS dependency, understanding this issue would be beneficial in improving my current setup. Any help offered would be greatly appreciated!

Answer №1

After exploring various options, I decided to switch gears and utilize Vue cli 3 instead. This tool streamlined the process of setting up a Vue project by incorporating the latest dependencies and reducing the need for multiple configuration files. Additionally, it offers native support for creating Vue projects with TypeScript integrated.

In addition, I transitioned from Visual Studio 2017 to Visual Studio Code. By embracing .vue files, I consolidated all HTML, TypeScript, and CSS code into a single file for each component - a much more efficient setup!

To sum it up, my recommendation is to opt for vue-cli-3: https://cli.vuejs.org/

I also suggest using Visual Studio Code over the bulkier Visual Studio for an enhanced coding experience.

Happy coding ahead!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to easily organize a TypeScript dictionary in a straightforward manner?

My typescript dictionary is filled with code. var dictionaryOfScores: {[id: string]: number } = {}; Now that it's populated, I want to sort it based on the value (number). Since the dictionary could be quite large, I'm looking for an in-place ...

Vue js image not displaying due to path issue

This project utilizes Laravel and Vue.js. The image directory is located in "public/images/products". Image data in the database is stored as "image":"images/products/image_name.jpg". The route path is set to "127.0.0.1:8000/product". When accessin ...

Ways to boost the smoothlife performance and framerate in p5js

I have a NextJS project using p5js deployed on . This project is an implementation of , which involves a cellular automata generalized on a continuous domain. Currently, it runs at around 10 to 14 frames per second and I aim to increase this. You can fin ...

How can I implement 'blocked tails' using the :after pseudo-element?

Apologies, I'm uncertain of the right term for these elements. I have a module that reveals another box with information when hovered over. I want them to be visually connected by an angled rectangle or tail to indicate their association. Something a ...

transitioning from a particular class to utilizing props in SCSS and Vue.js

Is there a way to dynamically apply classes based on props without duplicating SCSS code? When I duplicate the code and add the class, it works, but I want to be able to modify specific values by adding the appropriate class. Components :class="[theme === ...

Mapping an array of Type T in Typescript using typings

Suppose we have a type T: type T = { type: string, } and we create a function that takes an array of T and returns an object where the keys are the values of each T.type and the values are objects of type T. const toMap = (...args: T[]) => args.red ...

Incorporate the module into both the parent and child class

In my coding project, I have a situation where both a parent class and a child class are importing the same lodash library. This raises the question: will the final bundled JavaScript file contain duplicate lodash code? //Parent Class import Component fro ...

Overlaying text on several images

My challenge is centering text over multiple images using a combination of Bootstrap and CSS. While most online resources suggest using position: absolute; to achieve this, I have only been successful in centering the text in the middle of the screen rathe ...

Resolution for Reflected Diagonal Backdrop Design

Encountering a bug in Firefox with my mirrored diagonal background pattern. A vertical line appearing between left and right positioned elements at certain screen widths. Seeking a CSS solution or hack, no linked image files allowed. .stripes-background ...

Interactive front end design for decision trees

On the front end, I aim to enable users to influence the outcome of a Decision Tree based on their selections. For my Django-React App, I have adopted the style and tree example from the codeplayer. You can find it here: I am tasked with creating an unor ...

Refreshing issue: Model change in child page not updating view correctly (Ionic & Angular)

I am currently working with Ionic 3.20 and Angular 5.2.9, encountering an issue with content refreshing after a model change. Despite being new to this, I sense that I might be overlooking something fundamental. Within my view, I have the following elemen ...

Breaking the line in Vue JS allows for more organized and easier

Snippet of Vue.js code: getTitleText(){ let mainTitle = ""; let getTitle = this.titleText; let countGetTitle = getTitle.split(" ").length; if(countGetTitle > 4){ mainTitle = getTitle.replace(/(\S+\s*){1,4}/g, ...

Certain HTML elements on the webpage are not functioning properly when attempting to incorporate a div tag

One of the challenges I'm currently facing is that the links for HOME and ABOUT ME in the header section are not accessible when the 'data' div is added. Strangely, the DOWNLOAD and CONTACT ME links still work fine. This issue seems to be oc ...

Include a Vue component within another Vue component in a Laravel application using VueJs

I've recently integrated Vue.js into my Laravel project and encountered an issue when trying to call a component within another component. After running the command npm run dev, I received a webpack error. Here is the code snippet from my parent comp ...

Having issues with React Nivo tooltip functionality not functioning properly on specific graphs

While using Nivo ResponsivePie to visualize some data, everything is functioning properly except for the tooltip. For some reason, the tooltip isn't appearing as it should. Interestingly, I have a heatmap and a bar graph with tooltips that are working ...

Why does the method of type assigning vary between actual and generic types?

There are no errors in the code shown below: type C = {b: string}; class Class { data: C; constructor(data: C) { this.data = data; } test() { const hack: C & {a?: any} = this.data; //no error } } However, when a g ...

Is it better to keep a lengthy array in the back-end or front-end storage?

I'm facing a dilemma in my angular application. I have a lengthy array that I need to access easily from the front-end without causing any slowdowns. There are various options available, but I'm unsure which one would be the most efficient. Shoul ...

Deriving data types based on a variable in TypeScript

If I have a dictionary that links component names to their corresponding components like this: const FC1 = ({prop}: {prop: number}) => <>{prop}</>; const FC2 = ({prop}: {prop: string}) => <>{prop}</>; const mapComponents = [ ...

What is the trick to make the "@" alias function in a Typescript ESM project?

My current challenge involves running a script using ESM: ts-node --esm -r tsconfig-paths/register -T src/server/api/jobs/index.ts Despite my efforts, the script seems unable to handle imports like import '@/server/init.ts': CustomError: Cannot ...

I encountered an issue where I did not receive a response when utilizing res.write() within the fetch function

Currently, I am utilizing the <res.write()> method in nodejs at https://nodejs.org/api/http.html#responsewritechunk-encoding-callback. In addition to this, I am also implementing the fetch function which can be found at https://developer.mozilla.org/ ...