1

I would like to use a 3rd party plugin but can't get it to load with my webpack config because the vue-loader isn't configured properly ( I think ) Importing my own components which are in the project folder works.

import Paginate from 'vuejs-paginate/src/components/Paginate.vue' 

When trying to import a .vue file from a package I get this error:

(function (exports, require, module, __filename, __dirname) { <template> SyntaxError: Unexpected token < 

So I think the vue-loader doesn't work if I import a package which is within node_modules folder.

This is my webpack config:

const path = require('path') const webpack = require('webpack') const vueConfig = require('./vue-loader.config') const ExtractTextPlugin = require('extract-text-webpack-plugin') const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') const nodeExternals = require('webpack-node-externals') const isProd = process.env.NODE_ENV === 'production' module.exports = { devtool: isProd ? false : '#cheap-module-source-map', output: { path: path.resolve(__dirname, '../dist'), publicPath: '/dist/', filename: '[name].[chunkhash].js' }, resolve: { alias: { 'public': path.resolve(__dirname, '../public') } }, module: { noParse: /es6-promise\.js$/, // avoid webpack shimming process rules: [ { test: /\.vue$/, loader: 'vue-loader', options: vueConfig }, { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules\/, query: { plugins: ['transform-runtime'] } }, { test: /\.(png|jpg|gif|svg)$/, loader: 'url-loader', options: { limit: 10000, name: '[name].[ext]?[hash]' } }, { test: /\.css$/, use: isProd ? ExtractTextPlugin.extract({ use: 'css-loader?minimize', fallback: 'vue-style-loader' }) : ['vue-style-loader', 'css-loader'] } ] }, performance: { maxEntrypointSize: 300000, hints: isProd ? 'warning' : false }, plugins: isProd ? [ new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), new webpack.optimize.ModuleConcatenationPlugin(), new ExtractTextPlugin({ filename: 'common.[chunkhash].css' }) ] : [ new FriendlyErrorsPlugin() ] } 

vue-loader.config.js

module.exports = { extractCSS: process.env.NODE_ENV === 'production', preserveWhitespace: false, postcss: [ require('autoprefixer')({ browsers: ['last 3 versions'] }) ] } 

The node_modules is excluded but shouldn't it only be excluded for the babel-loader, not the vue loader itself ?

---- edit

I'm using SSR, the author itself states in this issue

@johnRivs Thank you so much. @sbefort You can import the library by import Paginate from 'vuejs-paginate/src/components/Paginate'; for SSR. Any question please reopen this issue.

1 Answer 1

1

You don't want to go into the NPM package internals.

When you do:

import Paginate from 'vuejs-paginate/src/components/Paginate.vue' 

notice you depend on vuejs-paginate's internals (src folder exists?) and such.

The propert way is to install the package and import what the package exposes.


For example, to install, run on shell:

npm install vuejs-paginate --save 

Then in your code, import and use like:

import Paginate from 'vuejs-paginate' Vue.component('paginate', Paginate) 

And WebPack will take care of the rest, independently (at least with regards to vuejs-paginat itself) from the vue-loader. And, yes, vue-loader should exclude node_modules because you don't want it to process every soucve .vue file of every package you import.

Sign up to request clarification or add additional context in comments.

5 Comments

I'm using SSR, github.com/lokyoung/vuejs-paginate/issues/44 - the author itself states @sbefort You can import the library by import Paginate from 'vuejs-paginate/src/components/Paginate'; for SSR.
@Ohgodwhy thanks for your constructive comment, but I did read it, not only the manual but also the issues, since it doesn't work for me I think it's my webpack conf.
@user345234674567 In your question you say you are including the extension .vue, like: import Paginate from 'vuejs-paginate/src/components/Paginate.vue'. Have you tried it without it, like import Paginate from 'vuejs-paginate/src/components/Paginate';?
@acdcjunior yes I've already tried that, can't find the module at all this way - Error: Cannot find module 'vuejs-paginate/src/components/Paginate' from '/home/user/ssr/dist'
Did you npm install --save vuejs-paginate?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.