Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

饿了么elementui按需引入文问题

  • 在使用vue配合webpack2打包时出现按需引入elementui组件找不到css样式文件,但是编绎是没有报错
    因为官方说法按需引入要使用.babelrc配制plugins选项

.babelrc配制如下


    {
    "presets": [
        ["es2015", { "modules": false }]
    ],
    "plugins": [
        ["component", [{
            "libraryName": "element-ui",
            "styleLibraryName": "theme-default"
        }]]
    ]
}

webpack配制如下

            {
                test: /.js$/,
                use: ['babel-loader'],
                exclude: /node_modules/
            },

引入时的代码

    import Vue from 'vue'
    import ResetCss from '../../assets/reset.css'
    import FontCss from '../../assets/font.css'
    // 完整引ele
    import { Button, Card, Form, Input, Checkbox, FormItem } from 'element-ui'
    import App from './App.vue'
    // 加载ele插件
    Vue.use(Button)
    Vue.use(Card)
    Vue.use(Form)
    Vue.use(Input)
    Vue.use(Checkbox)
    Vue.use(FormItem)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

再次排查webpack配制,发现是一个css loader出问题了,还有一定要配制好Extract-Text-Webpack-Plugin这个插件,不然会导致各种问题


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...