mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-12 03:38:07 +00:00
fix: transpile server not work (#4338)
This commit is contained in:
parent
ca5d53850b
commit
3abc9e815e
@ -2,7 +2,6 @@ import path from 'path'
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import defaultsDeep from 'lodash/defaultsDeep'
|
import defaultsDeep from 'lodash/defaultsDeep'
|
||||||
import defaults from 'lodash/defaults'
|
import defaults from 'lodash/defaults'
|
||||||
import escapeRegExp from 'lodash/escapeRegExp'
|
|
||||||
import pick from 'lodash/pick'
|
import pick from 'lodash/pick'
|
||||||
import isObject from 'lodash/isObject'
|
import isObject from 'lodash/isObject'
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
@ -319,18 +318,7 @@ export function getNuxtConfig(_options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// include SFCs in node_modules
|
|
||||||
options.build.transpile = [].concat(options.build.transpile || [])
|
options.build.transpile = [].concat(options.build.transpile || [])
|
||||||
.map(module => (module instanceof RegExp)
|
|
||||||
? module
|
|
||||||
: new RegExp(
|
|
||||||
escapeRegExp(
|
|
||||||
path.normalize(
|
|
||||||
module.replace(/\\/g, '/')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (options.build.quiet === true) {
|
if (options.build.quiet === true) {
|
||||||
consola.level = 0
|
consola.level = 0
|
||||||
|
@ -3,6 +3,7 @@ import consola from 'consola'
|
|||||||
import TimeFixPlugin from 'time-fix-plugin'
|
import TimeFixPlugin from 'time-fix-plugin'
|
||||||
import clone from 'lodash/clone'
|
import clone from 'lodash/clone'
|
||||||
import cloneDeep from 'lodash/cloneDeep'
|
import cloneDeep from 'lodash/cloneDeep'
|
||||||
|
import escapeRegExp from 'lodash/escapeRegExp'
|
||||||
import VueLoader from 'vue-loader'
|
import VueLoader from 'vue-loader'
|
||||||
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
||||||
import WebpackBar from 'webpackbar'
|
import WebpackBar from 'webpackbar'
|
||||||
@ -26,6 +27,7 @@ export default class WebpackBaseConfig {
|
|||||||
this.spinner = builder.spinner
|
this.spinner = builder.spinner
|
||||||
this.loaders = this.options.build.loaders
|
this.loaders = this.options.build.loaders
|
||||||
this.buildMode = this.options.dev ? 'development' : 'production'
|
this.buildMode = this.options.dev ? 'development' : 'production'
|
||||||
|
this.modulesToTranspile = this.normalizeTranspile()
|
||||||
}
|
}
|
||||||
|
|
||||||
get colors() {
|
get colors() {
|
||||||
@ -45,6 +47,20 @@ export default class WebpackBaseConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
normalizeTranspile() {
|
||||||
|
// include SFCs in node_modules
|
||||||
|
const items = [/\.vue\.js/]
|
||||||
|
for (const pattern of this.options.build.transpile) {
|
||||||
|
if (pattern instanceof RegExp) {
|
||||||
|
items.push(pattern)
|
||||||
|
} else {
|
||||||
|
const posixModule = pattern.replace(/\\/g, '/')
|
||||||
|
items.push(new RegExp(escapeRegExp(path.normalize(posixModule))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return items
|
||||||
|
}
|
||||||
|
|
||||||
getBabelOptions() {
|
getBabelOptions() {
|
||||||
const options = clone(this.options.build.babel)
|
const options = clone(this.options.build.babel)
|
||||||
|
|
||||||
@ -171,9 +187,7 @@ export default class WebpackBaseConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// item in transpile can be string or regex object
|
// item in transpile can be string or regex object
|
||||||
const modulesToTranspile = [/\.vue\.js/].concat(this.options.build.transpile)
|
return !this.modulesToTranspile.some(module => module.test(file))
|
||||||
|
|
||||||
return !modulesToTranspile.some(module => module.test(file))
|
|
||||||
},
|
},
|
||||||
use: perfLoader.js().concat({
|
use: perfLoader.js().concat({
|
||||||
loader: require.resolve('babel-loader'),
|
loader: require.resolve('babel-loader'),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
|
import escapeRegExp from 'lodash/escapeRegExp'
|
||||||
import nodeExternals from 'webpack-node-externals'
|
import nodeExternals from 'webpack-node-externals'
|
||||||
|
|
||||||
import WebpackBaseConfig from './base'
|
import WebpackBaseConfig from './base'
|
||||||
@ -9,6 +10,23 @@ import VueSSRServerPlugin from './plugins/vue/server'
|
|||||||
export default class WebpackServerConfig extends WebpackBaseConfig {
|
export default class WebpackServerConfig extends WebpackBaseConfig {
|
||||||
constructor(builder) {
|
constructor(builder) {
|
||||||
super(builder, { name: 'server', isServer: true })
|
super(builder, { name: 'server', isServer: true })
|
||||||
|
this.whitelist = this.normalizeWhitelist()
|
||||||
|
}
|
||||||
|
|
||||||
|
normalizeWhitelist() {
|
||||||
|
const whitelist = [
|
||||||
|
/\.css$/,
|
||||||
|
/\?vue&type=style/
|
||||||
|
]
|
||||||
|
for (const pattern of this.options.build.transpile) {
|
||||||
|
if (pattern instanceof RegExp) {
|
||||||
|
whitelist.push(pattern)
|
||||||
|
} else {
|
||||||
|
const posixModule = pattern.replace(/\\/g, '/')
|
||||||
|
whitelist.push(new RegExp(escapeRegExp(posixModule)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return whitelist
|
||||||
}
|
}
|
||||||
|
|
||||||
devtool() {
|
devtool() {
|
||||||
@ -69,11 +87,7 @@ export default class WebpackServerConfig extends WebpackBaseConfig {
|
|||||||
if (fs.existsSync(dir)) {
|
if (fs.existsSync(dir)) {
|
||||||
config.externals.push(
|
config.externals.push(
|
||||||
nodeExternals({
|
nodeExternals({
|
||||||
whitelist: [
|
whitelist: this.whitelist,
|
||||||
/\.css$/,
|
|
||||||
/\?vue&type=style/,
|
|
||||||
...this.options.build.transpile
|
|
||||||
],
|
|
||||||
modulesDir: dir
|
modulesDir: dir
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user