canopy-webpack-config 4.0.0-beta.3 → 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 +1 -0
- package/package.json +5 -2
- package/src/canopy-webpack-config.js +84 -61
package/.prettierrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/package.json
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "canopy-webpack-config",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
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",
|
|
18
|
+
"url": "^0.11.0",
|
|
16
19
|
"webpack-bundle-analyzer": "^4.7.0",
|
|
17
20
|
"webpack-merge": "^4.2.1"
|
|
18
21
|
}
|
|
@@ -1,56 +1,71 @@
|
|
|
1
|
-
const path = require(
|
|
2
|
-
const { CleanWebpackPlugin } = require(
|
|
3
|
-
const BundleAnalyzerPlugin =
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
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(
|
|
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 =
|
|
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 =
|
|
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 !==
|
|
22
|
-
throw new Error(
|
|
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 (
|
|
26
|
-
|
|
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:
|
|
56
|
+
type: "amd",
|
|
42
57
|
name: name,
|
|
43
58
|
},
|
|
44
|
-
path: path.resolve(process.cwd(),
|
|
45
|
-
chunkFilename:
|
|
59
|
+
path: path.resolve(process.cwd(), "build"),
|
|
60
|
+
chunkFilename: "[name].js",
|
|
46
61
|
},
|
|
47
|
-
mode: env.dev || isDevServer ?
|
|
62
|
+
mode: env.dev || isDevServer ? "development" : "production",
|
|
48
63
|
module: {
|
|
49
64
|
rules: [
|
|
50
65
|
{
|
|
51
|
-
test: /\.js
|
|
52
|
-
exclude: [path.resolve(process.cwd(),
|
|
53
|
-
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
|
-
|
|
66
|
-
|
|
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 ||
|
|
89
|
+
analyzerMode: env.analyze || "disabled",
|
|
73
90
|
}),
|
|
74
91
|
],
|
|
75
|
-
devtool:
|
|
92
|
+
devtool: "source-map",
|
|
76
93
|
externals: [
|
|
77
94
|
/^.+!sofe$/,
|
|
78
95
|
/^canopy-sofe-extensions$/,
|
|
@@ -92,36 +109,42 @@ module.exports = function(name, overridesConfig) {
|
|
|
92
109
|
/^sofe$/,
|
|
93
110
|
/^cp-analytics$/,
|
|
94
111
|
],
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
+
: {},
|
|
115
135
|
};
|
|
116
136
|
|
|
117
|
-
overridesConfig =
|
|
137
|
+
overridesConfig =
|
|
138
|
+
typeof overridesConfig === "function"
|
|
139
|
+
? overridesConfig(env)
|
|
140
|
+
: overridesConfig;
|
|
118
141
|
|
|
119
|
-
const finalConfig = merge.smart(defaultCanopyConfig, overridesConfig)
|
|
142
|
+
const finalConfig = merge.smart(defaultCanopyConfig, overridesConfig);
|
|
120
143
|
|
|
121
144
|
if (env.debug) {
|
|
122
|
-
console.log(finalConfig)
|
|
145
|
+
console.log(finalConfig);
|
|
123
146
|
}
|
|
124
147
|
|
|
125
|
-
return finalConfig
|
|
126
|
-
}
|
|
127
|
-
}
|
|
148
|
+
return finalConfig;
|
|
149
|
+
};
|
|
150
|
+
};
|