Autoprefixer support
Please, can you add support to process CSS files with autoprefixer in webpack configs?
Hmm. Is it sufficient to add the necessary postcss config in https://github.com/angular/angular-cli/blob/de3c27536d58a9f41418f988b70456d6bbaf24b5/packages/angular-cli/models/webpack-build-common.ts?
In that case it would be a matter of adding the following to the webpack plugins attribute:
var autoprefixer = require('autoprefixer');
// ...
new webpack.LoaderOptionsPlugin({
test: /\.css$/,
options: {
postcss: [ autoprefixer() ]
},
}),
At which point anyone can drop a browserslist file (https://github.com/ai/browserslist) in their project and autoprefixer will find it.
If that seems like a reasonable approach I'll try and find time to get a pr together
@SethDavenport & @filipesilva , what if we just add autoprefixer and support only the latest 2 browsers for now? so we could at least use flexbox without a hassle. I know this is not the best solution but we'd have some very basic support for now and as far as I see, the effort to achieve this is not big.
@SethDavenport that sounds like a sensible implementation, and the last two browsers also seems like a sensible default.
Remember that a test is also needed to ensure it's working, see https://github.com/angular/angular-cli/blob/master/tests/e2e/tests/build/styles/css.ts, add something that autoprefixer should prefix, and verify that it did.
@SethDavenport do you want to tackle this one ? If you don't have time I could add the prefixer, if you want of course. my company's shipping the first angular 2 app in the next few weeks and we're all happy if we have some basic support for the older browsers.
Hi @dimfried - looking at my calendar I probably won't get to it until the weekend. If you feel you can get to it first, go right ahead.
@dimfried If you have vs code, I use this extension as long as cli has no built in support for it: https://marketplace.visualstudio.com/items?itemName=mrmlnc.vscode-autoprefixer
Regarding browser versions: autoprefixer uses browserslist, so in theory not specifying anything should give you a default of > 1%, last 2 versions, Firefox ESR.
However if you project has a browserslist file in the top level of the source tree, or if you have a BROWSERSLIST environment variable, autoprefixer should pick it up:
See:
- https://github.com/postcss/autoprefixer#options
- https://github.com/ai/browserslist#queries
@filipesilva Having some issues running npm run test:e2e (this is prior to making any code changes). Is this something you've seen before?
Test "setup/100-npm-link" failed...
Running "npm link" returned error code 1...
STDOUT:
> [email protected] install /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/angular2-template-loader/node_modules/codecov/node_modules/execSync
> node install.js
[execsync v1.0.2] Attempting to compile native extensions.
[execSync v1.0.2]
Native code compile failed!!
> [email protected] install /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/compression-webpack-plugin/node_modules/node-zopfli
> node-pre-gyp install --fallback-to-build
[node-zopfli] Success: "/Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/compression-webpack-plugin/node_modules/node-zopfli/lib/binding/node-v48-darwin-x64/zopfli.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
> [email protected] install /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/node-sass
> node scripts/install.js
Start downloading binary at https://github.com/sass/node-sass/releases/download/v3.10.1/darwin-x64-48_binding.node
Binary downloaded and installed at /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/node-sass/vendor/darwin-x64-48/binding.node
> [email protected] install /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/fsevents
> node-pre-gyp install --fallback-to-build
[fsevents] Success: "/Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/fsevents/lib/binding/Release/node-v48-darwin-x64/fse.node" is installed via remote
> [email protected] postinstall /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/node-sass
> node scripts/build.js
"/Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/node-sass/vendor/darwin-x64-48/binding.node" exists.
testing binary.
Binary is fine; exiting.
Error: Running "npm link" returned error code 1...
STDOUT:
> [email protected] install /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/angular2-template-loader/node_modules/codecov/node_modules/execSync
> node install.js
[execsync v1.0.2] Attempting to compile native extensions.
[execSync v1.0.2]
Native code compile failed!!
> [email protected] install /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/compression-webpack-plugin/node_modules/node-zopfli
> node-pre-gyp install --fallback-to-build
[node-zopfli] Success: "/Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/compression-webpack-plugin/node_modules/node-zopfli/lib/binding/node-v48-darwin-x64/zopfli.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
> [email protected] install /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/node-sass
> node scripts/install.js
Start downloading binary at https://github.com/sass/node-sass/releases/download/v3.10.1/darwin-x64-48_binding.node
Binary downloaded and installed at /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/node-sass/vendor/darwin-x64-48/binding.node
> [email protected] install /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/fsevents
> node-pre-gyp install --fallback-to-build
[fsevents] Success: "/Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/fsevents/lib/binding/Release/node-v48-darwin-x64/fse.node" is installed via remote
> [email protected] postinstall /Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/node-sass
> node scripts/build.js
"/Users/Seth/code/oss/angular-cli/dist/angular-cli/node_modules/node-sass/vendor/darwin-x64-48/binding.node" exists.
testing binary.
Binary is fine; exiting.
at _exec (/Users/Seth/code/oss/angular-cli/tests/e2e/utils/process.ts:47:15)
at Object.npm (/Users/Seth/code/oss/angular-cli/tests/e2e/utils/process.ts:124:12)
at /Users/Seth/code/oss/angular-cli/tests/e2e/setup/100-npm-link.ts:30:50
I'm on node 6.8.1 and Mac OS X El Capitan (10.11.6)
I have the same issue on my machine. I created the PR last week but as long as tests are failing, I cannot send the PR. I have already wrote in Gitter, but didn't get a answer so far...
Hi
I had the same issue, and couldn't wait for angular-cli solution, and I dont want to fork it
so i did just (for scss in my case):
npm install --save-dev postcss postcss-cli postcss-scss autoprefixer
to install postcss-cli
and then Im running script on build, from package.json
"scripts": { ... "prefixcss": "postcss -s postcss-scss -u autoprefixer --autoprefixer.browsers \"last 2 versions\" -r src/**/*.scss" ... }
which is the same as
./node_modules/.bin/postcss -s postcss-scss -u autoprefixer --autoprefixer.browsers "last 2 versions" -r src/app/**/*.scss
caused from command line
this command modifies existing dev files but its not such a big problem, because last 2 versions of browsers almost do not need vendors
PS without scss command look like:
./node_modules/.bin/postcss -u autoprefixer --autoprefixer.browsers "last 2 versions" -r src/app/**/*.css
Hmmm - I'd like to get this in properly - how is CI passing for any PR if the e2e tests are broken? Are they working in Linux perhaps? I can try and spin up a VM.
@SethDavenport @dimfried I've never gotten that error myself, but I'm on Windows. Seems like npm link failed due to node-gyp trying to compile stuff? I don't use node-gyp myself either... maybe there's a way to deactivate it, or maybe just uninstalling if it's globally installed via npm.
Either way, if you can't run the tests locally you can still submit the PR and the CI will always run the test remotely. It sucks to wait for CI tests, but if you're fairly certain of what you're trying to do it's not that bad.
You can test locally on a project generated with ng new project-name --link-cli as well.
@KornelDylski can you provide me a hint, how can i use this also? https://github.com/Pavliko/postcss-svg
I'm sorry to comment on this, but I'm simply confused with the docs: does autoprefixer automatically works with a standard angular-cli setup or are there configuration steps (not ones to target specific browsers, but just standard) that one should follow?
Hi @picosam, autoprefixer should work automatically. Check out https://github.com/angular/angular-cli/wiki/stories-autoprefixer for further configuration options.
@LasTanzen It doesn't seem to work. I'm using SCSS as well, btw.
Hi @HassanAlthaf autoprefixer works fine for me. If you have issues, you should probably open a bug report with further description.
@LasTanzen I do not see any output from Autoprefixer when I build. Is it how I verify it works?