forked from WorldBrain/Memex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.js
117 lines (109 loc) · 3.32 KB
/
plugins.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { exec } from 'child_process'
import { EnvironmentPlugin } from 'webpack'
import ForkTsPlugin from 'fork-ts-checker-webpack-plugin'
import CopyPlugin from 'copy-webpack-plugin'
import HtmlPlugin from 'html-webpack-plugin'
import HtmlIncAssetsPlugin from 'html-webpack-include-assets-plugin'
import HardSourcePlugin from 'hard-source-webpack-plugin'
import StylelintPlugin from 'stylelint-webpack-plugin'
import BuildNotifPlugin from 'webpack-build-notifier'
import CssExtractPlugin from 'mini-css-extract-plugin'
import SentryPlugin from '@sentry/webpack-plugin'
import ZipPlugin from 'zip-webpack-plugin'
import PostCompilePlugin from 'post-compile-webpack-plugin'
// Disabling this for now as it adds 2-4 seconds to inc. build time - look into finding out why
// import WebExtReloadPlugin from 'webpack-chrome-extension-reloader'
import initEnv from './env'
import * as staticFiles from './static-files'
import { output } from './config'
/**
* @param {boolean} tslint Denotes whether or not to enable linting on this thread as well as type checking.
*/
const initTsPlugin = tslint =>
new ForkTsPlugin({
checkSyntacticErrors: true,
async: false,
tslint,
})
export default function({
webExtReloadPort = 9090,
mode = 'development',
template,
notifsEnabled = false,
isCI = false,
shouldPackage = false,
packagePath = '../dist',
extPackageName = 'extension.zip',
sourcePackageName = 'source-code.zip',
}) {
const plugins = [
new EnvironmentPlugin(initEnv({ mode })),
new CopyPlugin(staticFiles.copyPatterns),
new HtmlPlugin({
title: 'Popup',
chunks: ['popup'],
filename: 'popup.html',
template,
}),
new HtmlPlugin({
title: 'Memex',
chunks: ['options'],
filename: 'options.html',
template,
}),
new HtmlIncAssetsPlugin({
append: false,
assets: staticFiles.htmlAssets,
}),
new CssExtractPlugin({
filename: '[name].css',
}),
]
if (mode === 'development') {
plugins.push(
new HardSourcePlugin(),
// new WebExtReloadPlugin({
// port: webExtReloadPort,
// }),
)
} else if (mode === 'production') {
plugins.push(
new SentryPlugin({
release: process.env.npm_package_version,
include: output.path,
dryRun: !shouldPackage,
}),
)
}
// CI build doesn't need to use linting plugins
if (isCI) {
return [...plugins, initTsPlugin(false)]
}
if (notifsEnabled) {
plugins.push(
new BuildNotifPlugin({
title: 'Memex Build',
}),
)
}
if (shouldPackage) {
plugins.push(
new ZipPlugin({
path: packagePath,
filename: extPackageName,
exclude: [/\.map/],
}),
new PostCompilePlugin(() =>
exec('git archive -o dist/source-code.zip master'),
),
)
}
return [
...plugins,
initTsPlugin(true),
new StylelintPlugin({
files: 'src/**/*.css',
failOnError: mode === 'production',
}),
]
}