Skip to content

Commit 3c9105e

Browse files
authored
Add files via upload
1 parent 45ecd0e commit 3c9105e

21 files changed

+41196
-0
lines changed

bin/www.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const webpack = require('webpack');
5+
6+
const webpackDevMiddleware = require('webpack-dev-middleware');
7+
const webpackHotMiddleware = require('webpack-hot-middleware');
8+
const webpackHotServerMiddleware = require('webpack-hot-server-middleware');
9+
10+
const clientConfig = require('../webpack.client.dev.config');
11+
const serverConfig = require('../webpack.server.dev.config');
12+
13+
const express = require('express');
14+
15+
const logger = require('morgan');
16+
const favicon = require('serve-favicon');
17+
18+
const app = express();
19+
20+
const compiler = webpack([clientConfig,serverConfig]);
21+
22+
23+
let isListen = false;
24+
25+
compiler.hooks.done.tap('WebpackDevMiddleware', () => {
26+
if (!isListen) {
27+
isListen = true;
28+
29+
app.listen(3000, ()=>{
30+
console.info(`[server started] http://localhost:${3000}/`)
31+
});
32+
}
33+
});
34+
35+
36+
37+
app.use(logger('dev'));
38+
39+
app.use('/assets/', (req, res, next) => {
40+
let url = req.originalUrl.replace(/^\/assets\//, '/dest/');
41+
res.sendFile(path.join(process.env.PWD, url));
42+
43+
});
44+
// app.get('/assets/',express.static(path.join(__dirname, 'dest')));
45+
app.use(webpackDevMiddleware(compiler, {
46+
noInfo: true,
47+
serverSideRender:true,
48+
publicPath:clientConfig.output.publicPath
49+
}));
50+
51+
52+
app.use(webpackHotMiddleware(compiler.compilers[0],{
53+
reload:true,
54+
autoConnect:false
55+
}));
56+
app.use(webpackHotServerMiddleware(compiler, {
57+
serverRendererOptions: {
58+
}
59+
}));
60+
61+
62+
63+
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
const path = require('path');
2+
3+
const webpack = require('webpack');
4+
5+
const {DllPlugin} = webpack;
6+
7+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
8+
9+
const create = (root)=>({
10+
name: 'dll',
11+
mode: 'development',
12+
target:'web',
13+
context:path.join(root,'dest'),
14+
entry: {
15+
['root']: [
16+
'react',
17+
'react-dom',
18+
'react-router',
19+
// '@7rulnik/react-loadable',
20+
'react-router-dom',
21+
'redux',
22+
'react-redux',
23+
'redux-thunk',
24+
'redux-form',
25+
'prop-types',
26+
27+
],
28+
},
29+
devtool: 'none',
30+
output: {
31+
publicPath: "/static/",
32+
path: path.resolve(root, 'dest'),
33+
filename: "[name].dll.js",
34+
library:'[name]',
35+
libraryTarget: 'umd2',
36+
globalObject: "this"
37+
},
38+
resolve:{
39+
alias:{
40+
}
41+
},
42+
externals:{
43+
},
44+
module:{
45+
rules:[
46+
{
47+
test: /\.js$/,
48+
exclude: path.resolve(root, 'node_modules'),
49+
include: path.resolve(root, 'src'),
50+
},
51+
{
52+
test: /(\.ts|\.tsx)$/,
53+
use: [
54+
{
55+
loader:'awesome-typescript-loader',
56+
options: {
57+
configFileName:path.join(__dirname,'tsconfig.dev.ssr.client.json')
58+
}
59+
}
60+
],
61+
include: [path.join(__dirname,'src')],
62+
exclude: [/node_modules/, /\*\.spec.(ts|tsx)$/]
63+
},
64+
{
65+
test: /\.css$/,
66+
use: [
67+
MiniCssExtractPlugin.loader,
68+
// {loader: 'style-loader', options: {sourceMap: true}},
69+
{loader: 'css-loader', options: {sourceMap: true}},
70+
]
71+
},
72+
{
73+
test: /\.json$/,
74+
use: 'json-loader',
75+
exclude:[/node_modules/]
76+
},
77+
]
78+
},
79+
devtool: 'cheap-inline-module-source-map',
80+
plugins: [
81+
new DllPlugin({
82+
context: path.join(root,'dest'),
83+
name: "[name]",
84+
path: path.join(root, 'dest', '[name].dll.manifest.json'),
85+
}),
86+
new webpack.HotModuleReplacementPlugin()
87+
],
88+
});
89+
90+
91+
module.exports = {create};
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const path = require('path');
2+
3+
const webpack = require('webpack');
4+
5+
const {DllPlugin} = webpack;
6+
7+
module.exports = {
8+
name: 'dll',
9+
mode: 'development',
10+
context:path.join(__dirname,'dest'),
11+
entry: {
12+
['main']: [
13+
'react',
14+
'react-dom',
15+
'react-router',
16+
'react-router-dom',
17+
'redux',
18+
'react-redux',
19+
'redux-thunk',
20+
'redux-form',
21+
],
22+
},
23+
devtool: 'none',
24+
output: {
25+
publicPath: "/",
26+
path: path.join(__dirname, 'dest'),
27+
filename: "[name].dll.js",
28+
library:'[name]',
29+
libraryTarget: 'umd2',
30+
globalObject: "this"
31+
},
32+
plugins: [
33+
new DllPlugin({
34+
context: path.join(__dirname),
35+
name: "[name]",
36+
path: path.join(__dirname, 'dest', '[name].dll.manifest.json'),
37+
})
38+
],
39+
};

configs/webpack/webpack.utils.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports.externals = map => (context, request, callback) => {
2+
if (map.has(request)) {
3+
return callback(null, map.get(request));
4+
}
5+
callback();
6+
};

dest/loadable.manifest.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)