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

Commit d8c20f7

Browse files
committed
webpack config dev & prod now working
1 parent 580ffcd commit d8c20f7

File tree

7 files changed

+37
-6
lines changed

7 files changed

+37
-6
lines changed

buildScripts/srcServer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@ import path from 'path';
33
import open from 'open';
44
import { port, portUrl, openPort } from './customize/chalk';
55

6+
import webpack from 'webpack';
7+
import config from '../webpack.dev.config';
8+
import webpackDevMiddleware from 'webpack-dev-middleware';
9+
610
const app = express();
711

12+
const compiler = webpack(config);
13+
14+
app.use(webpackDevMiddleware(compiler, {
15+
publicPath: config.output.publicPath
16+
}));
17+
818
/*eslint-disable no-console*/
919

1020
app.use(express.static('src'));

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
"main": "buildScripts/srcServer.js",
66
"scripts": {
77
"prestart": "babel-node buildScripts/customize/startMsg.js",
8-
"start": "npm-run-all --parallel less webpack:watch open:src lint:watch",
8+
"start": "npm-run-all --parallel less open:src lint:watch",
99
"open:src": "babel-node buildScripts/srcServer.js",
1010
"lint": "esw webpack.config.* src buildScripts --color",
1111
"lint:watch": "npm run lint -- --watch",
1212
"less": "nodemon --exec lessc src/less/styles.less src/css/styles.css",
1313
"webpack:dev": "webpack --config webpack.dev.config.js",
14-
"webpack:watch": "webpack --watch"
14+
"webpack:watch": "webpack --watch",
15+
"build": "webpack --config webpack.prod.config.js"
1516
},
1617
"publishConfig": {
1718
"registry": "https://npm.pkg.github.com"

src/bundle.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,5 @@ <h1>CDN links:</h1>
5050
<a href="https://github.com/code-collabo/less-css-helper-library">less-css-helper-library repo</a>
5151
</button>
5252
</div>
53-
<script src="./bundle.js"></script>
5453
</body>
5554
</html>

webpack.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
const HtmlWebpackPlugin = require('html-webpack-plugin');
12

23
module.exports = {
3-
mode: 'none',
44
entry: './src/index.js',
5+
plugins: [
6+
new HtmlWebpackPlugin({
7+
template: 'src/index.html',
8+
inject: true,
9+
scriptLoading: 'blocking'
10+
})
11+
],
512
module: {
613
rules: [
714
{

webpack.dev.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ config.devtool = 'inline-source-map';
77

88
config.output = {
99
filename: 'bundle.js',
10-
path: path.resolve(__dirname, 'src')
10+
path: path.resolve(__dirname, 'src'),
11+
publicPath: '/'
1112
}
1213

1314
module.exports = config;

webpack.prod.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const path = require('path');
2+
3+
const config = require('./webpack.config');
4+
5+
config.mode = 'production';
6+
7+
config.devtool = 'source-map';
8+
9+
config.output = {
10+
filename: 'bundle.js',
11+
path: path.resolve(__dirname, 'dist')
12+
}
13+
14+
module.exports = config;

0 commit comments

Comments
 (0)