Skip to content

Commit

Permalink
webpack 5 just installed
Browse files Browse the repository at this point in the history
  • Loading branch information
wclr committed Jun 9, 2020
1 parent 326d0e2 commit e43dd99
Show file tree
Hide file tree
Showing 15 changed files with 7,018 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Why

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.
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.

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.

Expand Down Expand Up @@ -175,7 +175,7 @@ export interface LoaderOptions {

## Caveats

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.
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.

## How it works

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"wp4-build": "ts-node-dev webpack4/build",
"wp4-watch": "h --n lp-loader-wp4 -- ts-node-dev webpack4/watch",
"wp4-wds": "h --n lp-loader-wp4-wds -- ts-node-dev webpack4/wds",
"wp5-build": "ts-node-dev webpack5/build",
"wp5-watch": "h --n lp-loader-wp5 -- ts-node-dev webpack4/watch",
"wp5-wds": "h --n lp-loader-wp5-wds -- ts-node-dev webpack4/wds",
"test": "echo \"Error: no test specified\" && exit 1",
"prepublishOnly": "tsc"
},
Expand Down
2 changes: 1 addition & 1 deletion webpack4/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as webpack from 'webpack'
import * as path from 'path'
import * as fs from 'fs'

const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
import { LoaderOptions } from '../src/lp-loader'
Expand Down
8 changes: 8 additions & 0 deletions webpack5/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as webpack from 'webpack'
import { makeConfig } from './webpack.config'

const conf = makeConfig(true)
const compiler = webpack(conf)

compiler.run((err, stats) => {
})
10 changes: 10 additions & 0 deletions webpack5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "webpack5",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"webpack": "^5.0.0-beta.17",
"webpack-dev-server": "^3.11.0"
}
}
19 changes: 19 additions & 0 deletions webpack5/watch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as webpack from 'webpack'
import { makeConfig } from './webpack.config'
import * as http from 'http'
import { join } from 'path'
const staticServer = require('node-static').Server

const compiler = webpack(makeConfig(true))

compiler.watch({ poll: 100 }, (err, stats) => {
console.log(stats.toJson('minimal' as any))
})

const file = new staticServer(join(__dirname + '/build'))
console.log('Static HTTP server is listenting on', process.env.PORT)
http.createServer((request, response) => {
request.addListener('end', function () {
file.serve(request, response);
}).resume();
}).listen(process.env.PORT)
14 changes: 14 additions & 0 deletions webpack5/wds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as webpack from 'webpack'
import config from './webpack.config'
const WebpackDevServer = require('webpack-dev-server')

new WebpackDevServer(webpack(config), {
disableHostCheck: true,
hot: true,
stats: { colors: true },
port: process.env.PORT,
historyApiFallback: {
index: 'index.html',
}
})
.listen(process.env.PORT)
99 changes: 99 additions & 0 deletions webpack5/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import * as webpack from 'webpack'
import * as path from 'path'
import * as fs from 'fs'
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
import { LoaderOptions } from '../src/lp-loader'
export const makeConfig = (isProduction = false) => {
const isDevelopment = !isProduction

process.env.LP_DEBUG = 'true'

const appEntry = [
path.join(__dirname, '../app/app')
]

const buildDir = path.join(__dirname, 'build')
const tsLoaderOptions = {
compilerOptions: {
module: "esnext",
declaration: false,
moduleResolution: 'node'
}
}
const lpTsIndexFiles = /dict(\\|\/)index\.ts/
const lpLoader = path.join(__dirname, '../src/lp-loader')
const config: webpack.Configuration = {
//mode: 'development',
entry: {
app: appEntry
},
output: {
path: buildDir,
filename: '[name]-[hash].js',
chunkFilename: '[name]-[chunkhash].js',
publicPath: '/'
},
plugins: [
//new (webpack as any).NamedModulesPlugin(),
...isDevelopment ? [
new webpack.HotModuleReplacementPlugin()
] : [
new CleanWebpackPlugin([buildDir], {
root: path.resolve(__dirname, '../..')
})
],
new HtmlWebpackPlugin({
title: 'LP-Loader ' + (isDevelopment ? 'Dev' : 'Build'),
filename: 'index.html'
})
],
module: {
rules: [
{
test: lpTsIndexFiles, loaders: [
{}
{
loader: lpLoader, query: {
name: 'language.pack',
include: /(\\|\/)\w{2}\.ts/
} as LoaderOptions
},
//{ loader: 'ts-loader', query: tsLoaderOptions } as any
//{ loader: path.join(__dirname, 'ts-simple-loader'), query: tsLoaderOptions } as any
]
},
{
test: /\.ts$/,
loader: 'ts-loader',
//iexclude: [lpTsIndexFiles],
query: tsLoaderOptions
},
{ test: /\.css$/, loader: 'style!css' },
]
},
devtool: isDevelopment ? 'eval' : 'inline-source-map',
resolve: {
extensions: ['.ts', '.js'],
alias: {
//'lp': path.resolve(__dirname, '../../lib/lp-loader.ts'),
}
},
resolveLoader: {
extensions: ['.ts', '.js'],
alias: {
//'ts': 'awesome-typescript-loader'
//'ts': 'ts-loader'
},
modules: [
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, '../node_modules'),
path.resolve(__dirname, '../src'),
]
}
}

return config
}

export default makeConfig()
7 changes: 7 additions & 0 deletions webpack5/webpack3/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as webpack from 'webpack'
import { makeConfig } from './webpack.config'

const compiler = webpack(makeConfig(true))

compiler.run((err, stats) => {
})
14 changes: 14 additions & 0 deletions webpack5/webpack3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "webpack3",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@types/webpack": "^3.0.10",
"clean-webpack-plugin": "^0.1.16",
"html-webpack-plugin": "^2.30.1",
"ts-loader": "^2.3.4",
"webpack": "^3.5.5",
"webpack-dev-server": "^2.7.1"
}
}
19 changes: 19 additions & 0 deletions webpack5/webpack3/watch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as webpack from 'webpack'
import { makeConfig } from './webpack.config'
import * as http from 'http'
import { join } from 'path'
const staticServer = require('node-static').Server

const compiler = webpack(makeConfig(true))

compiler.watch({ poll: 100 }, (err, stats) => {
console.log(stats.toJson('minimal' as any))
})

const file = new staticServer(join(__dirname + '/build'))
console.log('Static HTTP server is listenting on', process.env.PORT)
http.createServer((request, response) => {
request.addListener('end', function () {
file.serve(request, response);
}).resume();
}).listen(process.env.PORT)
14 changes: 14 additions & 0 deletions webpack5/webpack3/wds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as webpack from 'webpack'
import config from './webpack.config'
const WebpackDevServer = require('webpack-dev-server')

new WebpackDevServer(webpack(config), {
disableHostCheck: true,
hot: true,
stats: { colors: true },
port: process.env.PORT,
historyApiFallback: {
index: 'index.html',
}
})
.listen(process.env.PORT)
92 changes: 92 additions & 0 deletions webpack5/webpack3/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import * as webpack from 'webpack'
import * as path from 'path'
import * as fs from 'fs'
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')

export const makeConfig = (isProduction = false) => {
const isDevelopment = !isProduction

const appEntry = [
path.join(__dirname, '../app/app')
]

isDevelopment && appEntry.push(
//'webpack-dev-server/client?http://localhost:' + process.env.PORT,
//'webpack/hot/only-dev-server'
)

const buildDir = path.join(__dirname, 'build')
const tsLoaderOptions = {
compilerOptions: {
module: "esnext",
declaration: false,
moduleResolution: 'node'
}
}
const lpTsIndexFiles = /dict(\\|\/)index.ts/
const config: webpack.Configuration = {
entry: {
app: appEntry
},
output: {
path: buildDir,
filename: '[name]-[hash].js',
//-[chunkhash]
chunkFilename: '[name]-[chunkhash].js',
publicPath: '/'
},
plugins: [
new CleanWebpackPlugin([buildDir], {
root: path.resolve(__dirname, '../..')
}),
new (webpack as any).NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
title: 'LP-Loader ' + (isDevelopment ? 'Dev' : 'Build'),
filename: 'index.html'
})
],
module: {
loaders: [
//{ test: /dict(\\|\/)index.js/, loader: 'lp-loader' },
{
test: lpTsIndexFiles, loaders: [
{ loader: path.join(__dirname, '../src/lp-loader'), query: { name: 'language.pack' } } as any,
{ loader: 'ts-loader', query: tsLoaderOptions } as any
]
},
{
test: /\.ts$/,
loader: 'ts-loader',
exclude: [lpTsIndexFiles],
query: tsLoaderOptions
},
{ test: /\.css$/, loader: 'style!css' },
]
},
devtool: 'eval',
resolve: {
extensions: ['.ts', '.js'],
alias: {
//'lp': path.resolve(__dirname, '../../lib/lp-loader.ts'),
}
},
resolveLoader: <any>{
extensions: ['.ts', '.js'],
alias: {
//'ts': 'awesome-typescript-loader'
//'ts': 'ts-loader'
},
modules: [
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, '../node_modules'),
path.resolve(__dirname, '../src'),
]
}
}

return config
}

export default makeConfig()
Loading

0 comments on commit e43dd99

Please sign in to comment.