-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (34 loc) · 1.12 KB
/
index.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
const { packageJson, install, copyFiles, makeDirs } = require("mrm-core");
const fs = require("fs");
const path = require("path");
module.exports = webpackTask;
function webpackTask() {
installDependencies();
writeFiles();
writePackageJsonScripts();
}
function installDependencies() {
const webpackPackages = ["webpack", "webpack-cli", "webpack-dev-server"];
const loaderPackages = ["babel-loader", "style-loader", "css-loader"];
const loaderDependencies = ["@babel/core", "@babel/preset-env"];
install([...webpackPackages, ...loaderPackages, ...loaderDependencies], {
yarn: true,
});
}
function writeFiles() {
copyFiles(path.join(__dirname, "templates"), "webpack.config.js");
copyFiles(path.join(__dirname, "templates"), "index.html");
makeDirs("src");
const indexJsPath = path.join("src", "index.js");
if (!fs.existsSync(indexJsPath)) {
fs.writeFileSync(indexJsPath, "");
console.info(`Create ${indexJsPath}`);
}
}
function writePackageJsonScripts() {
packageJson()
.setScript("start:dev", "webpack-dev-server")
.setScript("build:dev", "webpack")
.setScript("build", "webpack --mode production")
.save();
}