I want include all node_modules(and something else with my functionality) in the one file. This big file placed in ./src/sdk
. And i have other many components in the ./src/views/
and i want using all components separately, problem - any component should include inside self this big sdk.js, and if i using more then 1 component in the one page then sdk.js includes more then 1 time.
I have next webpack.config.js
const path = require("path");const HtmlWebpackPlugin = require('html-webpack-plugin');const clientEntries = { sdk: "./src/sdk" };glob.sync("./src/views/*.js").map(filePath => { const fileName = filePath.replace("./src/views/", "views/"); clientEntries[fileName.replace('.js', '')] = filePath;});module.exports = { entry: clientEntries, output: { filename: '[name].view.js', path: path.resolve(__dirname, 'dist') }, optimization: { splitChunks: { chunks: 'all' } }, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: { loader: "babel-loader" }, }, { test: /\.css$/, use: ["style-loader", "css-loader"] } ] }, plugins: [ new HtmlWebpackPlugin({ template: "./src/index.html", }) ]};
How i can compile ./src/sdk.js
and add him to
externals: { sdk: "./src/sdk"}
I want using multiple components without dublication code in the one page.