webpack更改.vue的扩展名

时间:2017-06-01 11:56:48

标签: webpack vue.js vue-component

您好我用vue和webpack创建了新项目,但我希望加载模板为.html而不是.vue。我收到错误'您可能需要一个合适的加载程序来处理这种文件类型'在webpack.base.conf.js我有



var path = require('path')
var utils = require('./utils')
var config = require('../config')
var vueLoaderConfig = require('./vue-loader.conf')

function resolve(dir) {
    return path.join(__dirname, '..', dir)
}

module.exports = {
    entry: {
        app: './src/main.js'
    },
    output: {
        path: config.build.assetsRoot,
        filename: '[name].js',
        publicPath: process.env.NODE_ENV === 'production' ?
            config.build.assetsPublicPath : config.dev.assetsPublicPath
    },
    resolve: {
        extensions: ['.js', '.html', '.json'],
        alias: {
            'html$': 'vue/dist/vue.esm.js',
            '@': resolve('src')
        }
    },
    module: {
        rules: [
            {
                test: /\.html$/,
                loader: 'vue-loader',
                options: vueLoaderConfig
      },
            {
                test: /\.js$/,
                loader: 'babel-loader',
                include: [resolve('src'), resolve('test')]
      },
            {
                test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
                loader: 'url-loader',
                options: {
                    limit: 10000,
                    name: utils.assetsPath('img/[name].[hash:7].[ext]')
                }
      },
            {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
                loader: 'url-loader',
                options: {
                    limit: 10000,
                    name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
                }
      }
    ]
    }
}




1 个答案:

答案 0 :(得分:1)

npm install -s html-loader

然后在webpack配置中,将其添加到其他规则:

{
  test: /\.html$/,
  use: 'html-loader',
},