vue webpack 2 autoprefixer for ie9 +

时间:2017-07-20 07:30:03

标签: webpack vue.js vuejs2 vue-cli

使用Vuecli生成的Vue和webpack构建。有很多魔法在继续。我无法弄清楚如何生成IE所需的供应商前缀。

这是从github问题复制的:https://github.com/vuejs-templates/webpack/issues/421#issuecomment-284322065

VUE-loader.conf.js

var utils = require('./utils')
var config = require('../config')
var isProduction = process.env.NODE_ENV === 'production'

module.exports = {
  loaders: utils.cssLoaders({
    sourceMap: isProduction
      ? config.build.productionSourceMap
      : config.dev.cssSourceMap,
    extract: isProduction
  }),
  postcss: [
    require('postcss-import')(),
    require('autoprefixer')({
      browsers: ['ie >= 9']
    })
  ]
}

简单容器组件示例

容器/ index.vue

<template>
    <div class="container">
        <slot></slot>
    </div>
</template>
<script>
    import './index.scss'
    export default {}
</script>

容器/ index.scss

// this is aliased in webpack.base.conf
@import "~styles/base-config";

.container {
  @include grid(); // this generates display:flex and border-box resets
  max-width: 100%;
  margin: 0 auto;
}

在头部生成的预期内联输出(但目前不能获取-ms-flexbox或-webkit-前缀)

<style> 
.container {
   -webkit-box-sizing: border-box; // not generated
   box-sizing: border-box; 
   display: -webkit-box;  // not generated
   display: -ms-flexbox; // not generated
   display: flex;
   max-width: 100%;
   margin: 0 auto;
}
</style>

相关:

  1. webpack2 vue-cli autoprefixer not work in js file when require scss file?

  2. https://github.com/vuejs/vue-cli/issues/350在vue-loader.conf.js中使用autoprefixer,最后2个版本(我使用browsers: ['ie >= 9'],没有工作)

  3. 潜在解决方案https://github.com/vuejs-templates/webpack/issues/600  但是在控制台中获取源映射错误。

  4. 添加到build / utils.js

    // npm install postcss-loader first then edit:
    ...
      var postcssLoader = {
        loader : 'postcss-loader'
      }
    
      // generate loader string to be used with extract text plugin
      function generateLoaders (loader, loaderOptions) {
        var loaders = [cssLoader, postcssLoader]
        if (loader) {
          loaders.push({
            loader: loader + '-loader',
            options: Object.assign({}, loaderOptions, {
              sourceMap: options.sourceMap
            })
          })
        }
    ...
    

    更新26-07-2017

    在此处添加了回购:https://github.com/sidouglas/vue-js-vendor-prefixes-bug

    更新03-08-2017

    @Chris Camaratta

    npm ERR! fetch failed http://uscavs-repo1:8081/artifactory/api/npm/npm-aggregator/vue/-/vue-2.4.2.tgz
    npm WARN retry will retry, error on last attempt: Error: getaddrinfo ENOTFOUND uscavs-repo1 uscavs-repo1:8081
    npm ERR! fetch failed http://uscavs-repo1:8081/artifactory/api/npm/npm-aggregator/vue-router/-/vue-router-2.7.0.tgz
    npm WARN retry will retry, error on last attempt: Error: getaddrinfo ENOTFOUND uscavs-repo1 uscavs-repo1:8081
    ^Z  ░░░░░░░░░░░░░░░⸩ ⠙ cloneCurrentTree: WARN retry will retry, error on last attempt: Error: getaddrinfo ENOTFOUND uscavs-repo1 uscavs-repo1:8081
    [2]  + 56232 suspended  npm i
    

1 个答案:

答案 0 :(得分:2)

我会采取一些不同的机智。 Vue / Webpack模板的源代码为here。它看起来与你上面发布的内容完全不同。在模板的配置中,您唯一需要做的就是“使用”packageslist中的“fieldslist”字段“(ref .postcssrc.js)。

作为实验,请尝试:

  1. this one
  2. 替换你的vue-loader.conf.js
  3. 将build / utils.js替换为this one
  4. 确保项目根目录中包含.postcssrc.js(以及package.json)。复制this one
  5. 在package.json中添加browserlist部分。再次, sample here
  6. 有关BrowserList规则的信息,look here