canopy-webpack-config 4.0.0-beta.2 → 4.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.prettierrc ADDED
@@ -0,0 +1 @@
1
+ {}
package/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "canopy-webpack-config",
3
- "version": "4.0.0-beta.2",
3
+ "version": "4.0.0-beta.4 ",
4
4
  "description": "Some defaults for webpack configs at canopy",
5
5
  "main": "src/canopy-webpack-config.js",
6
6
  "repository": "git@github.com:CanopyTax/canopy-webpack-config.git",
7
7
  "author": "Joel Denning <joel.denning@canopytax.com>",
8
8
  "license": "Apache-2.0",
9
- "devDependencies": {},
9
+ "devDependencies": {
10
+ "prettier": "^2.8.8"
11
+ },
10
12
  "peerDependencies": {
11
13
  "@babel/plugin-transform-runtime": ">=7",
12
14
  "@babel/runtime": ">=7"
13
15
  },
14
16
  "dependencies": {
15
17
  "clean-webpack-plugin": "^4.0.0",
16
- "webpack-bundle-analyzer": "^4.5.0",
18
+ "url": "^0.11.0",
19
+ "webpack-bundle-analyzer": "^4.7.0",
17
20
  "webpack-merge": "^4.2.1"
18
21
  }
19
22
  }
@@ -1,56 +1,71 @@
1
- const path = require('path')
2
- const { CleanWebpackPlugin } = require('clean-webpack-plugin')
3
- const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
4
- const merge = require('webpack-merge')
5
- const fs = require("fs")
6
- const homedir = require("os").homedir()
1
+ const path = require("path");
2
+ const { CleanWebpackPlugin } = require("clean-webpack-plugin");
3
+ const BundleAnalyzerPlugin =
4
+ require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
5
+ const merge = require("webpack-merge");
6
+ const fs = require("fs");
7
+ const homedir = require("os").homedir();
7
8
 
8
- let isDevServer = false
9
+ let isDevServer = false;
9
10
 
10
- if (process.argv.some(arg => arg.includes('serve'))) {
11
- isDevServer = true
11
+ if (process.argv.some((arg) => arg.includes("serve"))) {
12
+ isDevServer = true;
12
13
  }
13
14
 
14
- const hostIndex = process.argv.findIndex(arg => arg === "--host")
15
- const host = hostIndex >= 0 && process.argv[hostIndex + 1] ? process.argv[hostIndex + 1] : "0.0.0.0"
15
+ const hostIndex = process.argv.findIndex((arg) => arg === "--host");
16
+ const host =
17
+ hostIndex >= 0 && process.argv[hostIndex + 1]
18
+ ? process.argv[hostIndex + 1]
19
+ : "0.0.0.0";
16
20
 
17
- const portIndex = process.argv.findIndex(arg => arg === "--port")
18
- const port = portIndex >= 0 && process.argv[portIndex + 1] ? process.argv[portIndex + 1] : "8080"
21
+ const portIndex = process.argv.findIndex((arg) => arg === "--port");
22
+ const port =
23
+ portIndex >= 0 && process.argv[portIndex + 1]
24
+ ? process.argv[portIndex + 1]
25
+ : "8080";
19
26
 
20
- module.exports = function(name, overridesConfig) {
21
- if (typeof name !== 'string') {
22
- throw new Error('canopy-webpack-config expects a string name as the first argument')
27
+ module.exports = function (name, overridesConfig) {
28
+ if (typeof name !== "string") {
29
+ throw new Error(
30
+ "canopy-webpack-config expects a string name as the first argument"
31
+ );
23
32
  }
24
33
 
25
- if (typeof overridesConfig !== 'object' && typeof overridesConfig !== 'function') {
26
- throw new Error('canopy-webpack-config expects an object as a second argument to override the canopy defaults. Received ' + typeof overridesConfig)
34
+ if (
35
+ typeof overridesConfig !== "object" &&
36
+ typeof overridesConfig !== "function"
37
+ ) {
38
+ throw new Error(
39
+ "canopy-webpack-config expects an object as a second argument to override the canopy defaults. Received " +
40
+ typeof overridesConfig
41
+ );
27
42
  }
28
43
 
29
- return function(env) {
44
+ return function (env) {
30
45
  if (!env) {
31
- env = {}
46
+ env = {};
32
47
  }
33
48
 
34
49
  const defaultCanopyConfig = {
35
50
  entry: `./src/${name}.js`,
36
51
  output: {
37
52
  filename: `${name}.js`,
38
- publicPath: '',
53
+ publicPath: "",
39
54
  uniqueName: name,
40
55
  library: {
41
- type: 'amd',
56
+ type: "amd",
42
57
  name: name,
43
58
  },
44
- path: path.resolve(process.cwd(), 'build'),
45
- chunkFilename: '[name].js',
59
+ path: path.resolve(process.cwd(), "build"),
60
+ chunkFilename: "[name].js",
46
61
  },
47
- mode: env.dev || isDevServer ? 'development' : 'production',
62
+ mode: env.dev || isDevServer ? "development" : "production",
48
63
  module: {
49
64
  rules: [
50
65
  {
51
- test: /\.js?$/,
52
- exclude: [path.resolve(process.cwd(), 'node_modules')],
53
- loader: 'babel-loader',
66
+ test: /\.m?js$/,
67
+ exclude: [path.resolve(process.cwd(), "node_modules")],
68
+ loader: "babel-loader",
54
69
  options: {
55
70
  plugins: [
56
71
  // https://github.com/babel/babel-loader#babel-is-injecting-helpers-into-each-file-and-bloating-my-code
@@ -61,18 +76,20 @@ module.exports = function(name, overridesConfig) {
61
76
  ],
62
77
  },
63
78
  resolve: {
64
- modules: [
65
- process.cwd(),
66
- 'node_modules',
67
- ],
79
+ modules: [process.cwd(), "node_modules"],
80
+ fallback: {
81
+ url: require.resolve("url/"),
82
+ "react/jsx-runtime": "react/jsx-runtime.js",
83
+ "react/jsx-dev-runtime": "react/jsx-dev-runtime.js",
84
+ },
68
85
  },
69
86
  plugins: [
70
- new CleanWebpackPlugin({ verbose: isDevServer, }),
87
+ new CleanWebpackPlugin({ verbose: isDevServer }),
71
88
  new BundleAnalyzerPlugin({
72
- analyzerMode: env.analyze || 'disabled',
89
+ analyzerMode: env.analyze || "disabled",
73
90
  }),
74
91
  ],
75
- devtool: 'source-map',
92
+ devtool: "source-map",
76
93
  externals: [
77
94
  /^.+!sofe$/,
78
95
  /^canopy-sofe-extensions$/,
@@ -92,33 +109,42 @@ module.exports = function(name, overridesConfig) {
92
109
  /^sofe$/,
93
110
  /^cp-analytics$/,
94
111
  ],
95
- devServer: isDevServer ? {
96
- host: host,
97
- https: {
98
- cert: fs.readFileSync(`${homedir}/.canopy-ssl/public.pem`),
99
- key: fs.readFileSync(`${homedir}/.canopy-ssl/key.pem`)
100
- },
101
- allowedHosts: 'all',
102
- client: {
103
- webSocketURL: {
104
- hostname: host === "0.0.0.0" ? "localhost" : host, // Use localhost for the socket connection for CSP purposes
105
- port: port,
106
- },
107
- },
108
- headers: {
109
- "Access-Control-Allow-Origin": "*"
110
- },
111
- } : {}
112
+
113
+ devServer: isDevServer
114
+ ? {
115
+ host: host,
116
+ server: {
117
+ type: "https",
118
+ options: {
119
+ cert: fs.readFileSync(`${homedir}/.canopy-ssl/public.pem`),
120
+ key: fs.readFileSync(`${homedir}/.canopy-ssl/key.pem`),
121
+ },
122
+ },
123
+ allowedHosts: "all",
124
+ client: {
125
+ webSocketURL: {
126
+ hostname: host === "0.0.0.0" ? "localhost" : host, // Use localhost for the socket connection for CSP purposes
127
+ port: port,
128
+ },
129
+ },
130
+ headers: {
131
+ "Access-Control-Allow-Origin": "*",
132
+ },
133
+ }
134
+ : {},
112
135
  };
113
136
 
114
- overridesConfig = typeof overridesConfig === 'function' ? overridesConfig(env) : overridesConfig
137
+ overridesConfig =
138
+ typeof overridesConfig === "function"
139
+ ? overridesConfig(env)
140
+ : overridesConfig;
115
141
 
116
- const finalConfig = merge.smart(defaultCanopyConfig, overridesConfig)
142
+ const finalConfig = merge.smart(defaultCanopyConfig, overridesConfig);
117
143
 
118
144
  if (env.debug) {
119
- console.log(finalConfig)
145
+ console.log(finalConfig);
120
146
  }
121
147
 
122
- return finalConfig
123
- }
124
- }
148
+ return finalConfig;
149
+ };
150
+ };