我有一个由多个应用程序组成的项目,并且希望能够使用webpack 3.0(可以正常工作)使用全局webpack.config.js构建完整的项目。同时,我希望有本地webpack.config.js文件单独构建每个项目。项目结构如下:
- src
- project_1
...
webpack.config.js
...
- project_n
...
webpack.config.js
...
node_modules
webpack.config.js
显然,我不想复制项目子文件夹中的node_modules。如何从项目子文件夹的webpack.config.js引用全局node_modules文件夹?
我试过
resolve: {
modules: [path.resolve(__dirname,'../node_modules')]
},
在其中一个子文件夹webpack配置中,但我收到了很多类型错误
错误TS2304:找不到名称[...]
因为显然无法找到node_modules。
这是我对project_1的完整webpack.config.js:
var webpack = require('webpack');
const path = require("path")
module.exports = {
entry: path.resolve(__dirname, "src/project_1.ts"),
output: {
filename: "project_1_bundle.js",
path: path.resolve(__dirname, "bin")
},
externals: [
"angular",
"uuid",
{
"lodash": {
commonjs: "lodash",
amd: "lodash",
root: "_" // indicates global variable
}
},
{
"jquery": {
root: "$",
amd: "jquery",
commonjs: 'jquery'
}
},
{
"jquery-ui": {
amd: "jquery-ui",
commonjs: 'jquery-ui'
}
},
{
"Slick": {
root: "Slick",
amd: "Slick",
commonjs: 'Slick'
}
}
],
devtool: 'source-map',
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js'],
modules: [path.resolve(__dirname,'../node_modules')]
},
module: {
rules: [
{
enforce: 'pre',
test: /\.ts$/,
use: ['tslint-loader']
},
{
test: /\.tsx?$/,
use: ['ts-loader']
},
{
test: /\.html$/,
use: ['html-loader']
}
]
}
};