Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify Webpack Documentation #34

Open
timbomckay opened this issue Sep 26, 2022 · 2 comments
Open

Verify Webpack Documentation #34

timbomckay opened this issue Sep 26, 2022 · 2 comments

Comments

@timbomckay
Copy link

The documentation for Webpack didn't work for me

postcss-lit/README.md

Lines 33 to 60 in 48c6f36

### PostCSS with webpack
If you use webpack to execute postcss, you must ensure the right order of
loaders, like so:
```ts
module.exports = {
entry: './src/my-element.ts',
module: {
rules: [
{
test: /\.ts$/,
use: ['postcss-loader', 'ts-loader'],
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.ts']
},
output: {
filename: 'bundle.js'
}
};
```
This is important as postcss will transform your CSS _before_ typescript
transpiles to JS (which is what you want to happen).

When I switched it around it started working as expected. Here's our order:

{
  test: /\.ts$/,
  use: [
    'babel-loader',
    'ts-loader',
    'postcss-loader',
  ],
  exclude: /node_modules/
}

We're on Webpack version 5 in a monorepo, though I don't think that matters much.

After further investigation, as your readme states "postcss will transform your CSS before typescript transpiles", Webpack loaders are executed in reverse order (see Webpack's documentation). So we'd want postcss-loader last in the array so it can be first. I still don't understand why Webpack works this way, I'm sure there's a lengthy thread somewhere but it's illogical to me.

@43081j
Copy link
Owner

43081j commented Sep 29, 2022

how come you have a babel loader and a typescript loader? both transpile typescript.

and i do remember the whole 'reverse order' thing. ill try it myself at some point just to double check as im surprised it worked in the first place if thats the case (it did, i tested it many times). maybe i just got lucky 😂

@timbomckay
Copy link
Author

Yeah the babel & typescript config was written by someone before me, been meaning to review it haha. Probably could've left that out but it's what we have at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants