feat: Process transpile path (#4335)

This commit is contained in:
Amos Wong 2018-11-15 23:50:55 +08:00 committed by Clark Du
parent e21301f9b0
commit ae8dc96669
2 changed files with 21 additions and 6 deletions

View File

@ -2,6 +2,7 @@ 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'
@ -320,7 +321,16 @@ export function getNuxtConfig(_options) {
// include SFCs in node_modules // 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(module)) .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

View File

@ -1,3 +1,4 @@
import path from 'path'
import consola from 'consola' import consola from 'consola'
import { Builder, BundleBuilder, getPort, loadFixture, Nuxt, rp } from '../utils' import { Builder, BundleBuilder, getPort, loadFixture, Nuxt, rp } from '../utils'
@ -26,7 +27,9 @@ describe('basic dev', () => {
chunk: 'test-[name].[contenthash].js' chunk: 'test-[name].[contenthash].js'
}, },
transpile: [ transpile: [
'vue\\.test\\.js', '@scoped/packageA',
'@scoped\\packageB',
'vue.test.js',
/vue-test/ /vue-test/
], ],
loaders: { loaders: {
@ -60,10 +63,12 @@ describe('basic dev', () => {
test('Config: build.transpile', () => { test('Config: build.transpile', () => {
expect(transpile('vue-test')).toBe(true) expect(transpile('vue-test')).toBe(true)
expect(transpile('node_modules/test.js')).toBe(false) expect(transpile(path.normalize('node_modules/test.js'))).toBe(false)
expect(transpile('node_modules/vue-test')).toBe(true) expect(transpile(path.normalize('node_modules/vue-test'))).toBe(true)
expect(transpile('node_modules/vue.test.js')).toBe(true) expect(transpile(path.normalize('node_modules/vue.test.js'))).toBe(true)
expect(transpile('node_modules/test.vue.js')).toBe(true) expect(transpile(path.normalize('node_modules/test.vue.js'))).toBe(true)
expect(transpile(path.normalize('node_modules/@scoped/packageA/src/index.js'))).toBe(true)
expect(transpile(path.normalize('node_modules/@scoped/packageB/src/index.js'))).toBe(true)
}) })
test('Config: build.filenames', () => { test('Config: build.filenames', () => {