Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

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

vuecli2 升级到vuecli4,打包报错

项目由 vue-cli2.x 创建,目前打算升级到 @vue/cli 4,把老项目中所有文件拷贝过来,然后修改下 loader 的配置;npm run serve 运行后错误如下,实在是找不到原因了,高的头痛了;

image

补充 web.config.js 文件内容

const path = require('path');
const webpack = require('webpack')
require ('babel-polyfill')




function resolve (dir) {
  let result = path.join(__dirname, dir)
  // console.log(result);
  return result
}

function assetsPath (_path) {
  // let result = path.posix.join('public', _path)
  let result = path.posix.join('public', _path)
console.log(result);
  return result
}

module.exports = {

  configureWebpack: {
    resolve: {
      alias: {
        '@': resolve('src')
      },
      extensions: ['.js', '.vue', '.json'],
    }
  },
  lintOnSave: false,
  chainWebpack: config => {
    config.plugin('provide').use(webpack.ProvidePlugin, [{
      $: 'jquery',
      jquery: 'jquery',
      jQuery: 'jquery',
      'window.jQuery': 'jquery'
    }])


    config.module.rules.delete("svg"); //重点:删除默认配置中处理svg
    config.module
        .rule('svg-smart')
        .test(/.svg$/)
        .include
        .add(resolve('src/icons')) //处理svg目录
        .end()
        .use('svg-sprite-loader')
        .loader('svg-sprite-loader')
        .options({
            symbolId: 'icon-[name]'
        })

    config.module
    .rule('url-loader')
    .test(/.(png|jpe?g|gif|svg)(?.*)?$/)
    .exclude
    .add(resolve('src/icons')) //处理svg目录
    .end()
    .use('url-loader')
    .loader('url-loader')
    .options({
      limit: 10000,
      name: assetsPath('img/[name].[hash:7].[ext]')
    })

    config.module
    .rule('js')
    .test(/.js$/)
    .include
    .add(resolve('src'))
    .add(resolve('test'))
    .add(resolve('node_modules/webpack-dev-server/client'))
    .end()
    .use('babel-loader')
    .loader('babel-loader')

    config.module
    .rule('media')
    .test(/.(mp4|webm|ogg|mp3|wav|flac|aac)(?.*)?$/)
    .use('url-loader')
    .loader('url-loader')
    .options({
      limit: 10000,
      name: assetsPath('media/[name].[hash:7].[ext]')
    })
  


  }
};

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

1 Answer

0 votes
by (71.8m points)

卸载重装可以的


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...