UNPKG

6.3 kBJavaScriptView Raw
1import CopyWebpackPlugin from "copy-webpack-plugin";
2import TerserPlugin from "terser-webpack-plugin";
3import webpack from "webpack";
4import nodeExternals from "webpack-node-externals";
5import WebpackBar from "webpackbar";
6import { logDebugOutput } from "./debug";
7import { createAliases } from "./fragments/aliases";
8import { createDevtoolTemplates } from "./fragments/devtoolTemplate";
9import { createNodeOptions } from "./fragments/nodeOptions";
10import { createResolveOptions } from "./fragments/resolve";
11import { createResolveLoader } from "./fragments/resolveLoader";
12import { createDeduplicationAliases } from "./moduleDeduplication";
13import { resolveModulePaths } from "./modulePaths";
14import { createLoaders } from "./options/loaders";
15import { createPlugins } from "./plugins";
16function getNodeExternals() {
17 return [
18 (context, request, callback) => {
19 if (/config$/.test(request)) {
20 if (/next\/config$/.test(request) ||
21 /next-server\/config$/.test(request) ||
22 (/next-server/.test(context) && /\/runtime-config$/.test(request))) {
23 return callback(null, "commonjs " + "next-server/config");
24 }
25 }
26 if (/^webpack([\\//]|$)/.test(request)) {
27 return callback(null, "commonjs " + request);
28 }
29 if (/^next\-server([\\//]|$)/.test(request)) {
30 return callback(null, "commonjs " + request);
31 }
32 if (/^react([\\//]|$)/.test(request)) {
33 // console.log("Matched react: %s", request);
34 return callback(null, "commonjs " + request);
35 }
36 if (/^react-dom([\\//]|$)/.test(request)) {
37 // console.log("Matched react-dom: %s", request);
38 return callback(null, "commonjs " + request);
39 }
40 if (/^next([\\//]|$)/.test(request)) {
41 return callback(null, "commonjs " + request);
42 }
43 callback();
44 },
45 nodeExternals({
46 modulesFromFile: true,
47 whitelist: [/^@excitare/]
48 })
49 ];
50}
51export function createDevelopmentConfig(type, configuration) {
52 const modulePaths = resolveModulePaths(type, configuration, true);
53 const { entry, entryNextDir, entryGraphqlPath, entryServiceDir, cliPath, graphqlPath } = modulePaths;
54 const alias = {
55 ...createDeduplicationAliases(configuration, [configuration.entry, entryNextDir, entryServiceDir, entryGraphqlPath], configuration.bundleOptions.deduplication),
56 ...createAliases(type, modulePaths, "./")
57 };
58 logDebugOutput(modulePaths, type, configuration, alias, true);
59 const externals = [
60 "request",
61 "psl",
62 "hiredis",
63 "webpack",
64 "express",
65 "tslint",
66 "eslint",
67 "fork-ts-checker-webpack-plugin",
68 "moment-locales-webpack-plugin",
69 "moment-timezone-data-webpack-plugin",
70 "find-yarn-workspace-root",
71 "chalk",
72 "@zeit/next-mdx",
73 "duplicate-package-checker-webpack-plugin",
74 "lodash-webpack-plugin",
75 "next-size"
76 ];
77 const baseExternals = [
78 (_context, request, callback) => {
79 if (configuration.externals.includes(request)) {
80 return callback(null, "commonjs " + request);
81 }
82 if (externals.includes(request)) {
83 return callback(null, "commonjs " + request);
84 }
85 callback();
86 }
87 ];
88 return {
89 entry,
90 devtool: "source-map",
91 target: "node",
92 mode: "development",
93 resolve: createResolveOptions(alias),
94 resolveLoader: createResolveLoader(modulePaths, configuration, true),
95 output: {
96 path: configuration.outputDir,
97 filename: configuration.outputName,
98 pathinfo: true,
99 futureEmitAssets: true,
100 ...createDevtoolTemplates(configuration)
101 },
102 node: createNodeOptions(type),
103 optimization: type === "next"
104 ? {
105 minimize: true,
106 minimizer: [
107 new TerserPlugin({
108 cache: JSON.parse(process.env.terserDir),
109 parallel: false,
110 sourceMap: true,
111 terserOptions: {
112 ecma: 8,
113 mangle: false,
114 compress: {
115 defaults: false,
116 dead_code: true,
117 unused: true,
118 side_effects: true
119 }
120 }
121 })
122 ],
123 namedModules: true,
124 sideEffects: true,
125 usedExports: true,
126 providedExports: true,
127 removeEmptyChunks: true
128 }
129 : {
130 removeEmptyChunks: true
131 },
132 externals: type === "next" ? [...getNodeExternals(), ...baseExternals] : [...baseExternals],
133 module: {
134 rules: createLoaders(cliPath, graphqlPath, configuration, false)
135 },
136 plugins: [
137 ...createPlugins(configuration, true, modulePaths),
138 new WebpackBar({
139 name: configuration.name,
140 minimal: true
141 }),
142 new webpack.IgnorePlugin(/(big5\-added|shiftjis|eucjp|cp936|cp949|cp950)\.json$/, /iconv\-lite/),
143 new webpack.IgnorePlugin(/busboy\\deps\\encoding$/),
144 configuration.iconOptions != null
145 ? new CopyWebpackPlugin([
146 {
147 from: "**/*",
148 context: configuration.iconOptions.inputDir,
149 to: configuration.iconOptions.outDir,
150 toType: "dir"
151 }
152 ])
153 : null
154 ].filter(el => el != null)
155 };
156}
157//# sourceMappingURL=development.js.map
\No newline at end of file