kavu / webp-loader

WebP image loader & converter for Webpack
MIT License
93 stars 17 forks source link

error #3

Closed zhump closed 7 years ago

zhump commented 7 years ago

ERROR in ./~/vue-loader/lib/template-compiler?{"id":"data-v-f87c58e0"}!./~/vux-loader/src/before-template-compiler-loader.js!./~/vux-loader/src/template-loader.js!./~/vue-loader/lib/selector.js?type=template&index=0!./src/App.vue
Module not found: Error: Can't resolve 'webp' in '/Users/vivo/Documents/vscode_workspace/quick_start/vue/member_mobile'
 @ ./~/vue-loader/lib/template-compiler?{"id":"data-v-f87c58e0"}!./~/vux-loader/src/before-template-compiler-loader.js!./~/vux-loader/src/template-loader.js!./~/vue-loader/lib/selector.js?type=template&index=0!./src/App.vue 4:13-41
 @ ./src/App.vue
 @ ./src/main.js
kavu commented 7 years ago

@zhump can you show your webpack.config.js and package.json?

zhump commented 7 years ago

 ERROR  Failed to compile with 1 errors                                                                                                                          17:01:10

This dependency was not found:

* -!file-loader?name=[name].[hash].webp!../index.js?{quality: 50}!/Users/vivo/Documents/vscode_workspace/member_mobile/src/assets/1.png in ./src/assets/1.png

To install it, you can run: npm install --save -!file-loader?name=[name].[hash].webp!../index.js?{quality: 50}!/Users/vivo/Documents/vscode_workspace/member_mobile/src/assets/1.png

package.json

{
  "name": "member_mobile",
  "version": "1.0.0",
  "description": "A Vue.js project",
  "author": "xxxx <xxx@xxx.com>",
  "private": true,
  "scripts": {
    "dev": "node build/dev-server.js",
    "start": "node build/dev-server.js",
    "build": "node build/build.js"
  },
  "dependencies": {
    "fastclick": "^1.0.6",
    "vue": "^2.3.3",
    "vue-router": "^2.3.1",
    "vuex": "^2.3.1",
    "vuex-router-sync": "^4.2.0",
    "vux": "^2.5.1"
  },
  "devDependencies": {
    "autoprefixer": "^6.7.2",
    "babel-core": "^6.22.1",
    "babel-loader": "^6.2.10",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-preset-env": "^1.3.2",
    "babel-preset-stage-2": "^6.22.0",
    "babel-register": "^6.22.0",
    "chalk": "^1.1.3",
    "connect-history-api-fallback": "^1.3.0",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "^0.28.0",
    "eventsource-polyfill": "^0.9.6",
    "express": "^4.14.1",
    "extract-text-webpack-plugin": "^2.0.0",
    "file-loader": "^0.11.2",
    "friendly-errors-webpack-plugin": "^1.1.3",
    "html-webpack-plugin": "^2.28.0",
    "http-proxy-middleware": "^0.17.3",
    "less-loader": "^4.0.5",
    "multi-loader": "^0.1.0",
    "opn": "^4.0.2",
    "optimize-css-assets-webpack-plugin": "^1.3.0",
    "ora": "^1.2.0",
    "postcss-pxtorem": "^4.0.1",
    "rimraf": "^2.6.0",
    "semver": "^5.3.0",
    "shelljs": "^0.7.6",
    "url-loader": "^0.5.8",
    "vue-loader": "^12.1.0",
    "vue-style-loader": "^3.0.1",
    "vue-template-compiler": "^2.3.3",
    "vux-loader": "^1.1.1",
    "webp-loader": "^0.2.0",
    "webpack": "^2.6.1",
    "webpack-bundle-analyzer": "^2.2.1",
    "webpack-dev-middleware": "^1.10.0",
    "webpack-hot-middleware": "^2.18.0",
    "webpack-merge": "^4.1.0"
  },
  "engines": {
    "node": ">= 4.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

webpack.config.js

var path = require('path')
var utils = require('./utils')
var config = require('../config')
var vueLoaderConfig = require('./vue-loader.conf')
const vuxLoader = require('vux-loader');
var multi = require('multi-loader');
function resolve (dir) {
  return path.join(__dirname, '..', dir)
}

var webpackConfig = {
  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', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src')
    }
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        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]')
        }
      },
      {
        test: /\.(png|jpe?g)$/i,
        loader: multi(
          'file-loader?name=[name].[hash].webp!../index.js?{quality: 50}',
          'file-loader?name=[name].[hash].[ext]'
        )
      }
    ]
  }
}

module.exports = vuxLoader.merge(webpackConfig, {
  plugins: ['vux-ui', 'progress-bar', 'duplicate-style', {
      name: 'after-less-parser',
      fn: function (source) {
        if  (this.resourcePath.replace(/\\/g, '/').indexOf('/vux/src/components') > -1) {
          source = source.replace(/px/g, 'PX')
        }
        return source
      }
    },
    {
      name: 'style-parser',
      fn: function (source) {
        if (this.resourcePath.replace(/\\/g, '/').indexOf('/vux/src/components') > -1) {
          source = source.replace(/px/g, 'PX')
        }
        return source
      }
    } ]
})
kavu commented 7 years ago

Well, as I see you copied multi-loader example from the webp-loader test config:

        loader: multi(
          'file-loader?name=[name].[hash].webp!../index.js?{quality: 50}',
          'file-loader?name=[name].[hash].[ext]'
        )

It is wrong, but easy to fix.

        loader: multi(
          'file-loader?name=[name].[hash].webp!webp-loader?{quality: 50}',
          'file-loader?name=[name].[hash].[ext]'
        )

And don't forget to add loader to you devDependencies: npm i --save-dev webp-loader multi-loader.

bryantbiggs commented 7 years ago

*note the small typo for webp-loader

loader: multi(
          'file-loader?name=[name].[hash].webp!webp-loader?{quality: 50}',
          'file-loader?name=[name].[hash].[ext]'
        )
kavu commented 7 years ago

@bryantbiggs Thanks!