I have a project consisting of several apps and want to be able to build the complete project using a global webpack.config.js, with webpack 3.0 (which works). At the same time, I want to have local webpack.config.js files to build each project seperately. The project structure is as follows:
- src
- project_1
...
webpack.config.js
...
- project_n
...
webpack.config.js
...
node_modules
webpack.config.js
Obviously, I don't want to copy the node_modules in the project subfolders. How can I reference the global node_modules folder from the webpack.config.js of a project subfolder?
I tried
resolve: {
modules: [path.resolve(__dirname,'../node_modules')]
},
in one of the subfolder webpack configs but I get many errors of the type
error TS2304: Cannot find name [...]
because apparently node_modules cannot be located.
Here is my complete webpack.config.js for project_1:
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']
}
]
}
};