【发布时间】:2017-09-02 05:58:49
【问题描述】:
我正在使用yarn workspaces,其中根目录有一个包含我所有存储库的包目录。每个 repo 都有自己的 node_modules 目录,其中包含其依赖项。根 node_modules 目录包含整个项目的所有开发依赖项以及所有其他与开发相关的内容,例如 webpack.config 文件。 Webpack 使用热模块重新加载快速服务器包。
我遇到的问题是,如何配置 webpack externals 以排除整个项目中的所有 node_modules 目录,而不仅仅是根目录?
webpack-node-externals 在这种情况下似乎不起作用。
错误信息:
WARNING in ./packages/servers/express/node_modules/colors/lib/colors.js
127:29-43 Critical dependency: the request of a dependency is an expression
WARNING in ./packages/servers/express/node_modules/express/lib/view.js
79:29-41 Critical dependency: the request of a dependency is an expression
Webpack 配置:
const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const StartServerPlugin = require('start-server-webpack-plugin');
module.exports = {
entry: [
'babel-polyfill',
'webpack/hot/poll?1000',
path.join(__dirname, '../packages/servers/express/server/index.js')
],
watch: true,
target: 'node',
externals: [
nodeExternals({
whitelist: ['webpack/hot/poll?1000']
})
],
resolve: {
alias: {
handlebars: 'handlebars/dist/handlebars.js'
}
},
module: {
rules: [
{
test: /\.js?$/,
use: 'babel-loader',
exclude: /node_modules/
}
]
},
plugins: [
new StartServerPlugin('server.js'),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env': { BUILD_TARGET: JSON.stringify('server') }
})
],
output: {
path: path.join(__dirname, '../packages/servers/express/.build'),
filename: 'server.js'
}
};
【问题讨论】:
-
Workspaces 在标题中拼写错误。
标签: node.js express webpack yarnpkg