/
webpack.common.js
69 lines (65 loc) 路 2.09 KB
/
webpack.common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const fs = require("fs");
const ManifestBuilder = require("../utils/webpack/manifest-builder");
const SimpleCopyPlugin = require("../utils/webpack/simple-copy-plugin");
const WatchExtraFilesPlugin = require("../utils/webpack/watch-extra-files");
const { resolveBuildPath, resolveExtensionPath } = require("../utils/paths");
const { bundleName } = require("./constants");
const extensionPath = resolveExtensionPath();
const buildPath = resolveBuildPath();
const readmePath = resolveExtensionPath("README.md");
const copies = {
[bundleName]: [
{ from: readmePath, to: "README.md" }
]
};
const { eslintConfig, main: entryPoint } = require(resolveExtensionPath("package.json"));
const eslintEnabled = eslintConfig || fs.readdirSync(extensionPath).find(f => f.startsWith(".eslintrc"));
const jsLoaders = [{
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{
useBuiltIns: "usage",
corejs: 3,
modules: false, // Should be false to run tree shaking. See: https://webpack.js.org/guides/tree-shaking/
targets: {
chrome: 62,
safari: 11,
firefox: 59,
edge: 15
}
}
]
]
}
}];
if (eslintEnabled) {
jsLoaders.push("eslint-loader");
}
module.exports = {
mode: "none",
entry: { [bundleName]: entryPoint || "./src/index.js" },
output: {
path: buildPath,
library: "extension",
libraryExport: "default",
libraryTarget: "umd",
globalObject: "typeof self !== 'undefined' ? self : this"
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: jsLoaders
}]
},
plugins: [
new SimpleCopyPlugin(copies),
new WatchExtraFilesPlugin({
files: [resolveExtensionPath("package.json"), readmePath]
}),
new ManifestBuilder(extensionPath, bundleName)
]
};