Get one css file from webpack multiple entry points

Alexandra Vorobyova

I use webpack for my project. I have 2 entry points: the first one's for CSS files with CSS modules, the second - for global css files. Main.css isn't imported from any file in project so I made a special entry point for it.

const extractStylesCss = new ExtractTextPlugin('styles.css');  

entry: {
    'main': ["./src/index.tsx"],
    'styles': "./src/main.css"
},
module: {
    loaders: [ 
        {
            test: /^.*\.css$/,
            exclude: [
                path.join(__dirname, 'src/main.css')
            ],

            loader: extractStylesCss.extract(
                "style",
                `css?modules&importLoaders=2&localIdentName=[local]___[hash:base64:5]___${pjson.version}!typed-css-modules!postcss?pack=pure&sourceMap=inline`
            )
        },
        {
            test: /main\.css$/,
            loader: extractStylesCss.extract('style', 'css!postcss?pack=pure&sourceMap=inline')
        },
    ]
},
plugins: [
    extractStylesCss
],
output: {
    path: path.join(__dirname, "/docs"),
    filename: "[name].js"
}

I need only one output file - styles.css. I know that ExtractTextPlugin generates one bundle per entry point, but is there any possibility to get one file?

Michael Jungo

You had the right idea by adding it to the entry, unfortunately you created another bundle. Each property of the entry object creates a separate bundle, this is why you also get a style.js even though it only has the webpack bootstrap code in it and extract-text-webpack-plugin just overwrites the CSS file if you use the same output file for both.

What you really want is adding the main.css to the main bundle (it should conceptually be part of it, not in a separate bundle). The entries also accept an array with multiple entry points. With the following entry the CSS will automatically be combined:

entry: {
    main: ['./src/index.tsx', './src/main.css']
},

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to allow for webpack-dev-server to allow entry points from react-router

From Dev

How to compare multiple lines in one file and output a combined entry

From Dev

Browserify - multiple entry points

From Dev

Requirejs multiple modules from one file

From Dev

webpack keeps bundling react with each of the multiple entry points

From Dev

CSS - Include multiple fonts in one CSS file

From Dev

One big css file vs multiple small css files

From Dev

How do I insert records from one XML file into another at specific points based on multiple criteria?

From Dev

webpack build less files output one css minify file

From Dev

In webpack, how can I have different output directories for multiple entry points?

From Dev

get the value from an entry in a properties file via CSJS

From Dev

Webpack: Multiple entry points of different types (JS, HTML, LESS,...)

From Dev

Logging in a Python project with multiple points of entry

From Dev

How to use Webpack and Gulp with multiple entry points to transpile app and test directories?

From Dev

Webpack Multiple CSS Loaders

From Dev

Dynamically loading multiple entry points and splitting output

From Dev

How can I get multiple json data from json file one by one?

From Dev

PHP/MySQL - Get multiple fields from one entry in a table

From Dev

Can I (DNS) map one subdomain to multiple Play Framework entry points

From Dev

Develop C with multiple main entry points

From Dev

Copy entry from one keepass file to another

From Dev

How can I use awk to get value multiple times from one file to other file?

From Dev

Remove one IP from DNS entry with multiple IPs

From Dev

How to load only one entry of a cell from a .mat file in Matlab?

From Dev

Multiple entry points in GWTP

From Dev

Multiple values in one entry

From Dev

Building an array from a file with multiple data points

From Dev

Get specific points from matrix with one command

From Dev

Sass Loader for webpack: How to get CSS file instead of inline styles?

Related Related

  1. 1

    How to allow for webpack-dev-server to allow entry points from react-router

  2. 2

    How to compare multiple lines in one file and output a combined entry

  3. 3

    Browserify - multiple entry points

  4. 4

    Requirejs multiple modules from one file

  5. 5

    webpack keeps bundling react with each of the multiple entry points

  6. 6

    CSS - Include multiple fonts in one CSS file

  7. 7

    One big css file vs multiple small css files

  8. 8

    How do I insert records from one XML file into another at specific points based on multiple criteria?

  9. 9

    webpack build less files output one css minify file

  10. 10

    In webpack, how can I have different output directories for multiple entry points?

  11. 11

    get the value from an entry in a properties file via CSJS

  12. 12

    Webpack: Multiple entry points of different types (JS, HTML, LESS,...)

  13. 13

    Logging in a Python project with multiple points of entry

  14. 14

    How to use Webpack and Gulp with multiple entry points to transpile app and test directories?

  15. 15

    Webpack Multiple CSS Loaders

  16. 16

    Dynamically loading multiple entry points and splitting output

  17. 17

    How can I get multiple json data from json file one by one?

  18. 18

    PHP/MySQL - Get multiple fields from one entry in a table

  19. 19

    Can I (DNS) map one subdomain to multiple Play Framework entry points

  20. 20

    Develop C with multiple main entry points

  21. 21

    Copy entry from one keepass file to another

  22. 22

    How can I use awk to get value multiple times from one file to other file?

  23. 23

    Remove one IP from DNS entry with multiple IPs

  24. 24

    How to load only one entry of a cell from a .mat file in Matlab?

  25. 25

    Multiple entry points in GWTP

  26. 26

    Multiple values in one entry

  27. 27

    Building an array from a file with multiple data points

  28. 28

    Get specific points from matrix with one command

  29. 29

    Sass Loader for webpack: How to get CSS file instead of inline styles?

HotTag

Archive