-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
84 lines (77 loc) · 2.73 KB
/
webpack.config.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
const path = require("path");
const webpackModules = require("./webpack.modules");
const webpackPlugins = require("./webpack.plugins");
const webpackOptimization = require("./webpack.optimization");
const webpackDevServer = require("./webpack.devServer");
const dotenv = require("dotenv");
dotenv.config();
// grab theme name from package.json
const THEME_NAME = require("./package.json").name;
// detect if we're in dev mode
const DEV = process.env.NODE_ENV !== "production";
// webpack dev server port
const SERVER_PORT = 2222;
// paths
const SRC_PATH = path.join(__dirname, `./src`);
const PATHS = {
src: SRC_PATH,
scss: path.resolve(SRC_PATH, `scss`),
app: path.resolve(SRC_PATH, `js/App.js`),
dist: path.resolve(`./dist`),
public: `/wp-content/themes/${THEME_NAME}/dist/`
};
const config = {
mode: process.env.NODE_ENV,
devtool: DEV ? "eval" : "source-map",
optimization: webpackOptimization(DEV),
cache: {
type: "filesystem",
cacheDirectory: path.resolve(__dirname, ".webpack_cache")
},
//
// This allow loose imports from any file discarding its relative location to the import :
// ie: import { myModule } from "@modules/myModule";
//
resolve: {
alias: {
"@components": path.resolve(SRC_PATH, `js/components/`),
"@core": path.resolve(SRC_PATH, `js/core/`),
"@modules": path.resolve(SRC_PATH, `js/modules/`),
"@scroll": path.resolve(SRC_PATH, `js/scroll/`),
"@transitions": path.resolve(SRC_PATH, `js/transitions`),
"@ui": path.resolve(SRC_PATH, `js/ui/`),
"@utils": path.resolve(SRC_PATH, `js/utils/`),
"@vendors": path.resolve(SRC_PATH, `js/vendors/`),
"@mill3-sass": path.resolve(SRC_PATH, `scss/_lib/`),
"@mill3-sass-mixins": path.resolve(SRC_PATH, `scss/_lib/mixins/`),
"@mill3-sass-vars": path.resolve(SRC_PATH, `scss/_lib/vars/`),
"@mixins": path.resolve(SRC_PATH, `scss/mixins/`)
}
},
// main entries
entry: {
app: PATHS.app,
...(!DEV
? {
style: path.join(PATHS.scss, `App.scss`),
"editor-style": path.join(PATHS.scss, `Editor-style.scss`),
acfPreview: path.join(PATHS.scss, `ACF-preview.scss`),
acfPreviewIframe: path.resolve(SRC_PATH, `js/ACF-Preview.js`),
sentry: path.resolve(SRC_PATH, `js/Sentry.js`)
}
: {})
},
output: {
path: PATHS.dist,
filename: DEV ? `js/[name].bundle.js` : `js/[name].[chunkhash].bundle.js`,
chunkFilename: `js/[name].[chunkhash].bundle.js`,
publicPath: DEV ? `http://localhost:${SERVER_PORT}/` : PATHS.public
},
stats: {
loggingDebug: DEV ? ["sass-loader"] : []
},
...webpackDevServer(DEV, SERVER_PORT, PATHS),
module: webpackModules(DEV),
plugins: webpackPlugins(DEV, PATHS)
};
module.exports = config;