Skip to content

Commit e43dd99

Browse files
committed
webpack 5 just installed
1 parent 326d0e2 commit e43dd99

File tree

15 files changed

+7018
-3
lines changed

15 files changed

+7018
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Why
88

9-
Webpack is really a great Packager Manager and Bundler, despite all its caveats (mostly related to configuration and performance) it really gives has much more capabilities and puts less limitations on the user than any other bunder I've tried. But some (quite basic) higher level problems seem do be not solved even there.
9+
Webpack is really a great Packager Manager and Bundler, despite all its caveats (mostly related to configuration and performance) it gives has much more capabilities and puts less limitations on the user than any other bunder I've tried. But some (quite basic) higher level problems seem do be not solved even there.
1010

1111
All the methods of i18n of JS frontend apps (particularly loading/delivering language-specific usually UI-related data) I've seen out there - just ~~suck~~ could not satisfy my really basic requirements (which are mostly - simplicity and flexibility). Sounds strange, but feels like **no one knows how to make it right.** So, this package trying to approach the problem in a bit opinionated but at the same time flexible and generalized way. And this approach turned to be also useful for loading any kind of dictionary-like data sets.
1212

@@ -175,7 +175,7 @@ export interface LoaderOptions {
175175

176176
## Caveats
177177

178-
There are currently some problems with created bundle's names due to the problem that chunk names are not always available during the Webpack build. But this probably is going to be solved somehow.
178+
There are currently some problems with created bundle's names due to the fact that chunk/modules names are not always available when the loader performs. But this probably is going to be solved somehow.
179179

180180
## How it works
181181

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"wp4-build": "ts-node-dev webpack4/build",
1111
"wp4-watch": "h --n lp-loader-wp4 -- ts-node-dev webpack4/watch",
1212
"wp4-wds": "h --n lp-loader-wp4-wds -- ts-node-dev webpack4/wds",
13+
"wp5-build": "ts-node-dev webpack5/build",
14+
"wp5-watch": "h --n lp-loader-wp5 -- ts-node-dev webpack4/watch",
15+
"wp5-wds": "h --n lp-loader-wp5-wds -- ts-node-dev webpack4/wds",
1316
"test": "echo \"Error: no test specified\" && exit 1",
1417
"prepublishOnly": "tsc"
1518
},

webpack4/webpack.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as webpack from 'webpack'
22
import * as path from 'path'
3-
import * as fs from 'fs'
3+
44
const HtmlWebpackPlugin = require('html-webpack-plugin')
55
const CleanWebpackPlugin = require('clean-webpack-plugin')
66
import { LoaderOptions } from '../src/lp-loader'

webpack5/build.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as webpack from 'webpack'
2+
import { makeConfig } from './webpack.config'
3+
4+
const conf = makeConfig(true)
5+
const compiler = webpack(conf)
6+
7+
compiler.run((err, stats) => {
8+
})

webpack5/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "webpack5",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"webpack": "^5.0.0-beta.17",
8+
"webpack-dev-server": "^3.11.0"
9+
}
10+
}

webpack5/watch.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as webpack from 'webpack'
2+
import { makeConfig } from './webpack.config'
3+
import * as http from 'http'
4+
import { join } from 'path'
5+
const staticServer = require('node-static').Server
6+
7+
const compiler = webpack(makeConfig(true))
8+
9+
compiler.watch({ poll: 100 }, (err, stats) => {
10+
console.log(stats.toJson('minimal' as any))
11+
})
12+
13+
const file = new staticServer(join(__dirname + '/build'))
14+
console.log('Static HTTP server is listenting on', process.env.PORT)
15+
http.createServer((request, response) => {
16+
request.addListener('end', function () {
17+
file.serve(request, response);
18+
}).resume();
19+
}).listen(process.env.PORT)

webpack5/wds.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as webpack from 'webpack'
2+
import config from './webpack.config'
3+
const WebpackDevServer = require('webpack-dev-server')
4+
5+
new WebpackDevServer(webpack(config), {
6+
disableHostCheck: true,
7+
hot: true,
8+
stats: { colors: true },
9+
port: process.env.PORT,
10+
historyApiFallback: {
11+
index: 'index.html',
12+
}
13+
})
14+
.listen(process.env.PORT)

webpack5/webpack.config.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import * as webpack from 'webpack'
2+
import * as path from 'path'
3+
import * as fs from 'fs'
4+
const HtmlWebpackPlugin = require('html-webpack-plugin')
5+
const CleanWebpackPlugin = require('clean-webpack-plugin')
6+
import { LoaderOptions } from '../src/lp-loader'
7+
export const makeConfig = (isProduction = false) => {
8+
const isDevelopment = !isProduction
9+
10+
process.env.LP_DEBUG = 'true'
11+
12+
const appEntry = [
13+
path.join(__dirname, '../app/app')
14+
]
15+
16+
const buildDir = path.join(__dirname, 'build')
17+
const tsLoaderOptions = {
18+
compilerOptions: {
19+
module: "esnext",
20+
declaration: false,
21+
moduleResolution: 'node'
22+
}
23+
}
24+
const lpTsIndexFiles = /dict(\\|\/)index\.ts/
25+
const lpLoader = path.join(__dirname, '../src/lp-loader')
26+
const config: webpack.Configuration = {
27+
//mode: 'development',
28+
entry: {
29+
app: appEntry
30+
},
31+
output: {
32+
path: buildDir,
33+
filename: '[name]-[hash].js',
34+
chunkFilename: '[name]-[chunkhash].js',
35+
publicPath: '/'
36+
},
37+
plugins: [
38+
//new (webpack as any).NamedModulesPlugin(),
39+
...isDevelopment ? [
40+
new webpack.HotModuleReplacementPlugin()
41+
] : [
42+
new CleanWebpackPlugin([buildDir], {
43+
root: path.resolve(__dirname, '../..')
44+
})
45+
],
46+
new HtmlWebpackPlugin({
47+
title: 'LP-Loader ' + (isDevelopment ? 'Dev' : 'Build'),
48+
filename: 'index.html'
49+
})
50+
],
51+
module: {
52+
rules: [
53+
{
54+
test: lpTsIndexFiles, loaders: [
55+
{}
56+
{
57+
loader: lpLoader, query: {
58+
name: 'language.pack',
59+
include: /(\\|\/)\w{2}\.ts/
60+
} as LoaderOptions
61+
},
62+
//{ loader: 'ts-loader', query: tsLoaderOptions } as any
63+
//{ loader: path.join(__dirname, 'ts-simple-loader'), query: tsLoaderOptions } as any
64+
]
65+
},
66+
{
67+
test: /\.ts$/,
68+
loader: 'ts-loader',
69+
//iexclude: [lpTsIndexFiles],
70+
query: tsLoaderOptions
71+
},
72+
{ test: /\.css$/, loader: 'style!css' },
73+
]
74+
},
75+
devtool: isDevelopment ? 'eval' : 'inline-source-map',
76+
resolve: {
77+
extensions: ['.ts', '.js'],
78+
alias: {
79+
//'lp': path.resolve(__dirname, '../../lib/lp-loader.ts'),
80+
}
81+
},
82+
resolveLoader: {
83+
extensions: ['.ts', '.js'],
84+
alias: {
85+
//'ts': 'awesome-typescript-loader'
86+
//'ts': 'ts-loader'
87+
},
88+
modules: [
89+
path.resolve(__dirname, 'node_modules'),
90+
path.resolve(__dirname, '../node_modules'),
91+
path.resolve(__dirname, '../src'),
92+
]
93+
}
94+
}
95+
96+
return config
97+
}
98+
99+
export default makeConfig()

webpack5/webpack3/build.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as webpack from 'webpack'
2+
import { makeConfig } from './webpack.config'
3+
4+
const compiler = webpack(makeConfig(true))
5+
6+
compiler.run((err, stats) => {
7+
})

webpack5/webpack3/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "webpack3",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"@types/webpack": "^3.0.10",
8+
"clean-webpack-plugin": "^0.1.16",
9+
"html-webpack-plugin": "^2.30.1",
10+
"ts-loader": "^2.3.4",
11+
"webpack": "^3.5.5",
12+
"webpack-dev-server": "^2.7.1"
13+
}
14+
}

0 commit comments

Comments
 (0)