Description
This seems to be the same bug as #85, which was closed because, I quote, "Autoprefixer is in the latest template release", but we don't get Autoprefixer working for CSS or SCSS files outside of .vue
components.
Steps to reproduce:
vue init webpack postcss-test && cd postcss-test
npm install
npm install node-sass sass-loader --save-dev
Then create a few test stylesheets:
/* src/assets/test1.css */
.test1 { display: flex; }
// src/assets/test2.scss
.test2 { display: flex; }
Finally, let's test a few ways to load these:
- As entry points:
// build/webpack.base.conf.js
...
module.exports = {
entry: {
app: './src/main.js',
test1: './src/assets/test1.css',
test2: './src/assets/test2.scss'
},
...
}
Then npm run build
. Results:
/* dist/static/css/test1.ca0cd0e2b1b09d965f5ce5c21f1fc6e7.css */
.test1{display:flex}
/* dist/static/css/test2.4d716aeffa93f62596ef617b3129561c.css */
.test2{display:flex}
- As JS imports:
<!-- src/App.vue -->
<script>
import {} from './assets/test1.css'
import {} from './assets/test2.scss'
...
</script>
(Remove the entry points test before.) Then npm run build
. Result:
/* dist/static/css/app.4006533b8ed715dfd365cdd7a0b4f7be.css */
.test1,.test2{display:flex}
- In style tags in components:
<!-- src/App.vue -->
<style>
@import './assets/test1.css';
.test1b { display: flex; }
</style>
<style lang="scss">
@import './assets/test2.scss';
.test2b { display: flex; }
</style>
Result:
/* dist/static/css/app.6c438b7dca17522bb707d18112b8cbcb.css */
.test1{display:flex}.test1b,.test2,.test2b{display:-webkit-box;display:-ms-flexbox;display:flex}
Conclusion: Autoprefixer is only used for style tags inside .vue
components.
When using Sass or SCSS syntax and an external Sass/SCSS stylesheet, this can be used to apply Autoprefixer to code stored outside of components; the same trick does not work for CSS imports.
Was #85 closed based on a faulty assumption?
As a side note, debugging this issue proved difficult (for several team members) because this template comes with references to autoprefixer and postcss in two locations:
package.json
->"browserslist"
entry.postcssrc.js
But the config in config
and build
never references these locations, postcss or autoprefixer. It's all happening by magic, but only in very limited settings.
Maybe the brower list and postcss config should be moved to build/vue-loader.conf.js
, if it only applies to vue-loader? As it is, it's sending the message that it's a project-wide config, but in practice it doesn't seem to be.