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

wepy下用的什么打包工具呢,想要给CSS安装postcss, 请教下如何增加config #551

Closed
minhuang0 opened this issue Nov 21, 2017 · 7 comments
Labels
inactive Inactive issue, will be auto closed in 7 days

Comments

@minhuang0
Copy link

您好,我想要给我的wepy项目构建加上postcss, 但遇到点麻烦,试过下面两种方式都不行,找了issiue和Google,没有找到相关的配置文档;

var postcssSass = require('postcss-sass')
module.exports = {
    ...
   compilers: {
        sass: {
            outputStyle: 'compressed',
            parser: postcssSass
        }
   }
compilers: {
        sass: {
            outputStyle: 'compressed',
            plugins: [
                'postcss-css'
            ]
        }
}
@Gcaufy
Copy link
Collaborator

Gcaufy commented Nov 21, 2017

加postcss是为了处理什么 事情 呢?

@minhuang0
Copy link
Author

让打包后的css带上浏览器兼容的前缀

@Gcaufy
Copy link
Collaborator

Gcaufy commented Nov 21, 2017

两种方式,随便挑:
https://github.com/wepyjs/wepy/tree/master/packages/wepy-plugin-autoprefixer
https://github.com/wepyjs/wepy/wiki/WePY-%E4%BD%BF%E7%94%A8less-autoprefix

@Gcaufy Gcaufy closed this as completed Nov 21, 2017
@minhuang0
Copy link
Author

minhuang0 commented Nov 21, 2017

感谢作者的及时回复和帮忙解决问题;👍👍

用的第一种方式,因为没有用less, wepy-plugin-autoprefixer这个插件有一个bug:
在源文件(未被wepy编译前)里面包含wxss文件的时候,会有前面这种情况发生,导致block打包,改成scss后缀可以成功编译,估计可能pluging的顺序有关系;
在用了wxui.wxss,wxParse.wxss这种情况下,也可以通过修改为scss文件可以完成打包,但这应该不是比较好的解决方案;

目前的wepy.config.js比较简单,就一个pugling, 应该不是config的原因,引用的wxiui.wxss, wxParse.wxss应该也问题不大;

const path = require('path')
var prod = process.env.NODE_ENV === 'production'

module.exports = {
    wpyExt: '.wpy',
    build: {
        web: {
            htmlTemplate: path.join('src', 'index.template.html'),
            htmlOutput: path.join('web', 'index.html'),
            jsOutput: path.join('web', 'index.js')
        }
    },
    resolve: {
        alias: {
            counter: path.join(__dirname, 'src/components/counter'),
            '@': path.join(__dirname, 'src')
        },
        modules: ['node_modules']
    },
    eslint: true,
    compilers: {
        sass: {
            outputStyle: 'compressed',
            plugins: []
        },
        babel: {
            sourceMap: true,
            presets: [
                'env'
            ],
            plugins: [
                'transform-class-properties',
                'transform-decorators-legacy',
                'transform-object-rest-spread',
                'transform-export-extensions'
            ]
        }
    },
    plugins: {
        'autoprefixer': {
            filter: /\.wxss$/,
            config: {
                browsers: ['last 11 iOS versions']
            }
        }
    },
    appConfig: {
        noPromiseAPI: ['createSelectorQuery']
    }
}

if (prod) {
    delete module.exports.compilers.babel.sourcesMap
    // 压缩sass
    // module.exports.compilers['sass'] = {outputStyle: 'compressed'}

    // 压缩less
    module.exports.compilers['less'] = { compress: true }

    // 压缩js
    module.exports.plugins = {
        uglifyjs: {
            filter: /\.js$/,
            config: {
            }
        },
        imagemin: {
            filter: /\.(jpg|png|jpeg)$/,
            config: {
                jpg: {
                    quality: 80
                },
                png: {
                    quality: 80
                }
            }
        }
    }
}

@Gcaufy Gcaufy reopened this Nov 21, 2017
@evanyangg
Copy link

请问一下,我可以添加postcss-cssnext 这一类的postcss插件吗? 是否支持呢

@stale
Copy link

stale bot commented Jun 13, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
因为这个 Issue 最近没有任何有效回复,所以被自动标记为了stale。 如果在未来7天依旧没有任何激活操作,那么该 Issue 将会被自动关闭。 感谢您的提问。

@stale stale bot added the inactive Inactive issue, will be auto closed in 7 days label Jun 13, 2018
@stale stale bot closed this as completed Jun 20, 2018
@yangfan-coder
Copy link

你好,我用的less打包为什么我按照教程安装后使用开发者工具看还是没有 css前缀呢?
less-plugin-autoprefix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inactive Inactive issue, will be auto closed in 7 days
Projects
None yet
Development

No branches or pull requests

4 participants