【问题标题】:I cannot add Autoprefixer to a Express project我无法将 Autoprefixer 添加到 Express 项目
【发布时间】:2016-08-29 04:55:36
【问题描述】:

我无法将 Autoprefixers 添加到 postcssmidelware,如文档 https://github.com/sass/node-sass-middleware 中所述

我也一直在尝试使用 express-autoprefixers,但我仍然没有在我的 dest 或 public 文件夹中看到供应商:这里也是我的 repo (nodeauth/app.js) git@github.com 的链接:Lidofernandez/Projects-based-on-node.git

代码如下:

var sassMiddleware = require('node-sass-middleware');
var postcssMiddleware = require('postcss-middleware');
var autoprefixer = require('autoprefixer');

var app = express();

// styles engine setup
app.set('port', process.env.PORT || 3000);
app.use(
  sassMiddleware({
    src: path.join(__dirname, '/stylesheets/sass'),
    dest: path.join(__dirname, '/public/stylesheets'),
    debug: true,
    outputStyle: 'compressed',
    prefix: '/stylesheets'
  })
);
app.use(
  postcssMiddleware({
    plugins: [autoprefixer({browsers: ['> 1%', 'IE 7'], cascade: false})],
    options: {
      map: {
        inline: false
      }
    },
    src: function(req) {
      return path.join(__dirname, '/public/stylesheets', req.url);
    }
  })
);

【问题讨论】:

    标签: javascript node.js express sass


    【解决方案1】:

    最后我想通了:

    所以问题是我必须指定放置样式的文件夹:)

    app.use(
      '/stylesheets', postcssMiddleware({
        src: function(req) {
          return path.join(__dirname, 'public', 'stylesheets', req.path);
        },
        plugins: [
          autoprefixer()
        ],
        options: {
          map: {
            inline: false
          }
        }
      }
    ));
    

    【讨论】:

    • 这对我有用。谢谢!只是澄清一下:src 选项中的路径必须是完整文件的路径,而不仅仅是目录。
    猜你喜欢
    • 2020-04-25
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多