use webpack-node-externals

This commit is contained in:
EGOIST 2017-05-24 21:04:17 +08:00
parent 7a46135624
commit 3acf300416
3 changed files with 12 additions and 18 deletions

View File

@ -2,9 +2,9 @@
import webpack from 'webpack'
import VueSSRServerPlugin from 'vue-server-renderer/server-plugin'
import nodeExternals from 'webpack-node-externals'
import base from './base.config.js'
import { each, uniq } from 'lodash'
import { existsSync, readFileSync } from 'fs'
import { each } from 'lodash'
import { resolve } from 'path'
/*
@ -33,6 +33,12 @@ export default function () {
performance: {
hints: false
},
externals: [
nodeExternals({
// load non-javascript files with extensions, presumably via loaders
whitelist: [/\.(?!(?:js|json)$).{1,5}$/i]
})
],
plugins: (config.plugins || []).concat([
new VueSSRServerPlugin({
filename: 'server-bundle.json'
@ -54,18 +60,6 @@ export default function () {
})
)
}
// Externals
const nuxtPackageJson = require('../../package.json')
const projectPackageJsonPath = resolve(this.dir, 'package.json')
config.externals = Object.keys(nuxtPackageJson.dependencies || {})
if (existsSync(projectPackageJsonPath)) {
try {
const projectPackageJson = JSON.parse(readFileSync(projectPackageJsonPath))
config.externals = config.externals.concat(Object.keys(projectPackageJson.dependencies || {}))
} catch (e) {}
}
config.externals = config.externals.concat(this.options.build.vendor)
config.externals = uniq(config.externals)
// Extend config
if (typeof this.options.build.extend === 'function') {

View File

@ -96,7 +96,8 @@
"webpack": "^2.5.1",
"webpack-bundle-analyzer": "^2.8.1",
"webpack-dev-middleware": "^1.10.2",
"webpack-hot-middleware": "^2.18.0"
"webpack-hot-middleware": "^2.18.0",
"webpack-node-externals": "^1.6.0"
},
"devDependencies": {
"ava": "^0.19.1",
@ -120,8 +121,7 @@
"nyc": "^10.3.2",
"request": "^2.81.0",
"request-promise-native": "^1.0.4",
"std-mocks": "^1.0.1",
"webpack-node-externals": "^1.6.0"
"std-mocks": "^1.0.1"
},
"collective": {
"type": "opencollective",

View File

@ -6248,7 +6248,7 @@ webpack-hot-middleware@^2.18.0:
webpack-node-externals@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/webpack-node-externals/-/webpack-node-externals-1.6.0.tgz#232c62ec6092b100635a3d29d83c1747128df9bd"
resolved "https://registry.npmjs.org/webpack-node-externals/-/webpack-node-externals-1.6.0.tgz#232c62ec6092b100635a3d29d83c1747128df9bd"
webpack-sources@^0.1.0:
version "0.1.5"