From ba791ae5ad2c37ae911c6509d4431b99533cc0db Mon Sep 17 00:00:00 2001 From: Uttam Krishna Ukkoji Date: Wed, 30 Mar 2022 14:39:42 +0530 Subject: [PATCH] Web pack update --- .npmignore | 5 +++++ global.js | 1 + package.json | 28 ++++++++++++++++------------ webpack/webpack.nativescript.js | 7 ++++++- webpack/webpack.node.js | 5 +++++ webpack/webpack.react-native.js | 14 +++++++++++++- webpack/webpack.web.js | 11 ++++++++++- 7 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 global.js diff --git a/.npmignore b/.npmignore index 857e966e..cf2dc799 100644 --- a/.npmignore +++ b/.npmignore @@ -14,3 +14,8 @@ webpack jest.config.js coverage CODEOWNERS +src +.env +*.tgz +.talismanrc +tap-html.html \ No newline at end of file diff --git a/global.js b/global.js new file mode 100644 index 00000000..843e452a --- /dev/null +++ b/global.js @@ -0,0 +1 @@ +// module.exports = window; \ No newline at end of file diff --git a/package.json b/package.json index f142228a..ab591646 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "contentstack", - "version": "3.15.0", + "version": "3.15.1", "description": "Contentstack Javascript SDK", "homepage": "https://www.contentstack.com/", "author": { @@ -8,6 +8,7 @@ "url": "https://www.contentstack.com/" }, "main": "dist/node/contentstack.js", + "react-native": "dist/react-native/contentstack.js", "browser": "dist/web/contentstack.js", "types": "./index.d.ts", "_id": "contentstack@3.15.0", @@ -75,32 +76,35 @@ "babel-runtime": "6.26.0", "clean-webpack-plugin": "^4.0.0", "compression-webpack-plugin": "1.0.1", + "dotenv": "^16.0.0", "es3ify-loader": "0.2.0", "fetch-mock-jest": "^1.3.0", "http-proxy-agent": "^3.0.0", "istanbul": "^0.4.5", - "jest": "^27.2.5", - "jest-html-reporters": "^2.1.6", - "jsdoc": "^3.6.7", - "jshint": "^2.13.1", + "jest": "^27.5.1", + "jest-html-reporters": "^2.1.7", + "jsdoc": "^3.6.10", + "jshint": "^2.13.4", "node-request-interceptor": "^0.6.3", - "nodemailer": "^6.6.5", + "nodemailer": "^6.7.3", "request": "^2.88.2", "string-replace-loader": "1.3.0", "string-replace-webpack-plugin": "0.1.3", "tap-html": "^1.0.1", "tap-json": "1.0.0", "tape": "4.8.0", - "ts-jest": "^27.0.0-next.12", - "typescript": "^4.4.3", + "terser-webpack-plugin": "^5.3.1", + "ts-jest": "^27.1.4", + "typescript": "^4.6.3", "uglify-js": "2.8.29", - "webpack": "^5.59.0", - "webpack-cli": "^4.9.0", + "webpack": "^5.70.0", + "webpack-cli": "^4.9.2", "webpack-md5-hash": "0.0.5", - "webpack-merge": "4.1.0" + "webpack-merge": "4.1.0", + "webpack-node-externals": "^3.0.0" }, "dependencies": { - "@contentstack/utils": "^1.1.0", + "@contentstack/utils": "^1.1.1", "es6-promise": "^4.1.1", "isomorphic-fetch": "^3.0.0", "localStorage": "1.0.3" diff --git a/webpack/webpack.nativescript.js b/webpack/webpack.nativescript.js index 830e2e6f..711b1766 100755 --- a/webpack/webpack.nativescript.js +++ b/webpack/webpack.nativescript.js @@ -2,17 +2,22 @@ const path = require('path'); const webpackMerge = require('webpack-merge'); +var nodeExternals = require('webpack-node-externals'); const commonConfig = require('./webpack.common.js'); module.exports = function(options) { return webpackMerge(commonConfig(), { output: { - library: "Contentstack", libraryTarget: "commonjs2", path: path.join(__dirname, "../dist/nativescript"), filename: "contentstack.js" }, + target: "node", + externals: [nodeExternals()], + externalsPresets: { + node: true + }, resolve: { alias: { runtime: path.resolve(__dirname, '../src/runtime/nativescript') diff --git a/webpack/webpack.node.js b/webpack/webpack.node.js index f760b9f4..1c07a7d8 100755 --- a/webpack/webpack.node.js +++ b/webpack/webpack.node.js @@ -1,6 +1,7 @@ 'use strict'; const path = require('path'); const webpackMerge = require('webpack-merge'); +var nodeExternals = require('webpack-node-externals'); const commonConfig = require('./webpack.common.js'); @@ -12,6 +13,10 @@ module.exports = function(options) { filename: "contentstack.js" }, target: "node", + externals: [nodeExternals()], + externalsPresets: { + node: true + }, resolve: { alias: { runtime: path.resolve(__dirname, '../src/runtime/node') diff --git a/webpack/webpack.react-native.js b/webpack/webpack.react-native.js index a50f5a10..2e68a0e9 100755 --- a/webpack/webpack.react-native.js +++ b/webpack/webpack.react-native.js @@ -2,13 +2,14 @@ const path = require('path'); const webpackMerge = require('webpack-merge'); +const TerserPlugin = require("terser-webpack-plugin"); +var nodeExternals = require('webpack-node-externals'); const commonConfig = require('./webpack.common.js'); module.exports = function(options) { return webpackMerge(commonConfig(), { output: { - library: "Contentstack", libraryTarget: "commonjs2", path: path.join(__dirname, "../dist/react-native"), filename: "contentstack.js" @@ -23,6 +24,17 @@ module.exports = function(options) { 'node_modules', ] }, + target: 'node', + externals: [nodeExternals()], + externalsPresets: { + node: true + }, + optimization: { + minimize: true, + minimizer: [new TerserPlugin({ + terserOptions: { output: { ascii_only: true } } + })], + }, module: { rules: [{ test: /\.js?$/, diff --git a/webpack/webpack.web.js b/webpack/webpack.web.js index 5245411d..f2deb532 100755 --- a/webpack/webpack.web.js +++ b/webpack/webpack.web.js @@ -4,6 +4,7 @@ const path = require('path'); const webpackMerge = require('webpack-merge'); const commonConfig = require('./webpack.common.js'); +const webpack = require('webpack'); module.exports = function(options) { return webpackMerge(commonConfig(), { @@ -35,6 +36,14 @@ module.exports = function(options) { } }], }] - } + }, + node: { + global: false + }, + plugins: [ + new webpack.ProvidePlugin({ + global: require.resolve('./../global.js') + }) + ] }); } \ No newline at end of file