Open bskimball opened 7 years ago
In order to get around this issue, I altered my nuxt.config.js to transpile the @nuxtjs directory in node_modules using babel on build. Specifically look at the exclude on the extend function in the build configuration.
Below is an example of my nuxt.config.js.
module.exports = {
/*
** Headers of the page
*/
head: {
title: 'starter',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: 'Nuxt.js project' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
/*
** Customize the progress-bar color
*/
loading: { color: '#20a0ff' },
plugins: [
'~/plugins/vue-observe-visibility',
'~/plugins/vue-scrollto'
],
modules: [
'@nuxtjs/axios',
'@nuxtjs/blog'
],
/*
** Build configuration
*/
build: {
/*
** Babel
*/
babel: {
'presets': ['vue-app'],
'plugins': [
['component', [{
'libraryName': 'element-ui',
'styleLibraryName': 'theme-default'
}]]
],
'comments': false
},
/*
** Run ESLINT on save
*/
extend (config, ctx) {
if (ctx.isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
config.module.rules.push({
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules(?!(\/|\\)@nuxtjs)/,
options: Object.assign({}, this.babelOptions)
})
}
}
}
I'm sure there is a cleaner way to do this.
I've been using it here (https://github.com/znck/znck.github.io/blob/dev/nuxt.config.js), your can use it as reference.
I'll look into it by the weekend.
No worries. It works fine when I added the node_modules exclusion. I was working on just adding it directly in to my Nuxt set up (instead of a module), so I could change the templates.
I had this problem recently with vue-cli's pwa template (not nuxt). I had to do a very similar fix, I can't see any way around it. I used include
instead of exclude
though (it's probably safer). Specifically, we got the error when trying to import pretty-bytes.
We were already transpiling stuff in certain directories like src
and test
. So we wanted to also transpile some problematic (i.e. 2015+) dependencies. Long story short, we ended up with this:
const babelLoaderIncludes = [resolve('src'), resolve('test')];
if (config.dependenciesToTranspile) {
babelLoaderIncludes.push(...config.dependenciesToTranspile.map(require.resolve));
}
//......
{
test: /\.js$/,
loader: 'babel-loader',
include: babelLoaderIncludes,
},
(require.resolve
is the safest way to do it so it gets the full path, no matter where you are)
Nuxt rc11 Blog-module 0.0.1-6 on build Uglify fails
Looks like the code in the mixins is not run through babel before uglify tries to do what it needs to do, therefore is fails because it does not recognize the es6 arrow functions