Skip to content
This repository was archived by the owner on Oct 19, 2021. It is now read-only.

Commit e21b1c8

Browse files
authored
Merge pull request #4 from code-collabo/configure-webpack
3 - Configure dev environment & webpack
2 parents 0eeed10 + d8c20f7 commit e21b1c8

20 files changed

+7006
-390
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env"
4+
]
5+
}

.eslintrc.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"root": true,
3+
"parser": "@babel/eslint-parser",
4+
"extends": [
5+
"eslint:recommended",
6+
"plugin:import/warnings",
7+
"plugin:import/warnings"
8+
],
9+
"parserOptions": {
10+
"ecmaVersion": 7,
11+
"sourceType": "module"
12+
},
13+
"env": {
14+
"browser": true,
15+
"node": true
16+
},
17+
"ignorePatterns": ["src/bundle.js"],
18+
"rules": {
19+
"no-console": 1
20+
}
21+
}

buildScripts/customize/chalk.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import chalk from 'chalk';
2+
3+
//index.js
4+
export const dummyMsg = 'Testing dummy page...';
5+
6+
//srcServer.js
7+
export const port = 3000;
8+
export const portUrl = `http://localhost:${port}`;
9+
export const openPort = chalk.greenBright('Open:', chalk.blueBright(portUrl));
10+
11+
//startMsg.js
12+
export const startMsg = chalk.greenBright('Starting', chalk.blueBright('less-css-helper-library') +' in dev mode');

buildScripts/customize/startMsg.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { startMsg } from './chalk';
2+
3+
console.log(startMsg);

buildScripts/srcServer.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import express from 'express';
2+
import path from 'path';
3+
import open from 'open';
4+
import { port, portUrl, openPort } from './customize/chalk';
5+
6+
import webpack from 'webpack';
7+
import config from '../webpack.dev.config';
8+
import webpackDevMiddleware from 'webpack-dev-middleware';
9+
10+
const app = express();
11+
12+
const compiler = webpack(config);
13+
14+
app.use(webpackDevMiddleware(compiler, {
15+
publicPath: config.output.publicPath
16+
}));
17+
18+
/*eslint-disable no-console*/
19+
20+
app.use(express.static('src'));
21+
22+
app.get('/', (req, res) => {
23+
res.sendFile(path.join(__dirname, '../src/index.html'));
24+
});
25+
26+
app.listen(port, err => {
27+
if (err) {
28+
console.log(err);
29+
} else {
30+
console.log(openPort);
31+
open(portUrl);
32+
}
33+
});

0 commit comments

Comments
 (0)