piral-cli-webpack5 1.0.0-pre.1960 → 1.0.1-beta.5640
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +31 -10
- package/extend-config.js +125 -18
- package/lib/actions.d.ts +2 -2
- package/lib/actions.js +33 -39
- package/lib/actions.js.map +1 -1
- package/lib/{configs → enhancers/hmr-webpack-config-enhancer}/HotModuleServerPlugin.js +1 -1
- package/lib/enhancers/hmr-webpack-config-enhancer/HotModuleServerPlugin.js.map +1 -0
- package/lib/enhancers/hmr-webpack-config-enhancer/index.d.ts +5 -0
- package/lib/enhancers/hmr-webpack-config-enhancer/index.js +30 -0
- package/lib/enhancers/hmr-webpack-config-enhancer/index.js.map +1 -0
- package/lib/enhancers/html5-entry-webpack-config-enhancer/helpers.d.ts +2 -2
- package/lib/enhancers/html5-entry-webpack-config-enhancer/helpers.js +1 -1
- package/lib/enhancers/html5-entry-webpack-config-enhancer/helpers.js.map +1 -1
- package/lib/enhancers/html5-entry-webpack-config-enhancer/index.d.ts +2 -1
- package/lib/enhancers/html5-entry-webpack-config-enhancer/index.js +17 -6
- package/lib/enhancers/html5-entry-webpack-config-enhancer/index.js.map +1 -1
- package/lib/enhancers/pilet-webpack-config-enhancer/helpers.d.ts +5 -0
- package/lib/enhancers/pilet-webpack-config-enhancer/helpers.js +53 -1
- package/lib/enhancers/pilet-webpack-config-enhancer/helpers.js.map +1 -1
- package/lib/enhancers/pilet-webpack-config-enhancer/index.d.ts +18 -4
- package/lib/enhancers/pilet-webpack-config-enhancer/index.js +117 -49
- package/lib/enhancers/pilet-webpack-config-enhancer/index.js.map +1 -1
- package/lib/enhancers/piral-instance-webpack-config-enhancer/helpers.js +2 -0
- package/lib/enhancers/piral-instance-webpack-config-enhancer/helpers.js.map +1 -1
- package/lib/enhancers/piral-instance-webpack-config-enhancer/index.d.ts +2 -3
- package/lib/enhancers/piral-instance-webpack-config-enhancer/index.js +6 -7
- package/lib/enhancers/piral-instance-webpack-config-enhancer/index.js.map +1 -1
- package/lib/helpers.d.ts +2 -1
- package/lib/helpers.js +10 -4
- package/lib/helpers.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/SheetLoader.d.ts +1 -0
- package/lib/plugins/SheetLoader.js +19 -0
- package/lib/plugins/SheetLoader.js.map +1 -0
- package/lib/plugins/SheetPlugin.d.ts +7 -0
- package/lib/plugins/SheetPlugin.js +31 -0
- package/lib/plugins/SheetPlugin.js.map +1 -0
- package/lib/plugins/StylesLoader.d.ts +1 -0
- package/lib/plugins/StylesLoader.js +14 -0
- package/lib/plugins/StylesLoader.js.map +1 -0
- package/lib/plugins/StylesPlugin.d.ts +6 -0
- package/lib/plugins/StylesPlugin.js +34 -0
- package/lib/plugins/StylesPlugin.js.map +1 -0
- package/lib/webpack/bundler-run.d.ts +2 -21
- package/lib/webpack/bundler-run.js +54 -46
- package/lib/webpack/bundler-run.js.map +1 -1
- package/lib/webpack/common.d.ts +8 -0
- package/lib/webpack/common.js +104 -0
- package/lib/webpack/common.js.map +1 -0
- package/lib/webpack/pilet.d.ts +19 -0
- package/lib/webpack/pilet.js +97 -0
- package/lib/webpack/pilet.js.map +1 -0
- package/lib/webpack/piral.d.ts +16 -0
- package/lib/webpack/piral.js +90 -0
- package/lib/webpack/piral.js.map +1 -0
- package/package.json +28 -29
- package/src/actions.ts +33 -20
- package/src/{configs → enhancers/hmr-webpack-config-enhancer}/HotModuleServerPlugin.ts +1 -1
- package/src/enhancers/hmr-webpack-config-enhancer/index.ts +34 -0
- package/src/enhancers/html5-entry-webpack-config-enhancer/helpers.ts +7 -7
- package/src/enhancers/html5-entry-webpack-config-enhancer/index.ts +31 -19
- package/src/enhancers/pilet-webpack-config-enhancer/helpers.ts +62 -0
- package/src/enhancers/pilet-webpack-config-enhancer/index.ts +187 -59
- package/src/enhancers/piral-instance-webpack-config-enhancer/helpers.ts +2 -0
- package/src/enhancers/piral-instance-webpack-config-enhancer/index.ts +14 -18
- package/src/helpers.ts +15 -5
- package/src/index.ts +1 -1
- package/src/plugins/SheetLoader.ts +16 -0
- package/src/plugins/SheetPlugin.ts +34 -0
- package/src/plugins/StylesLoader.ts +11 -0
- package/src/plugins/StylesPlugin.ts +35 -0
- package/src/webpack/bundler-run.ts +60 -56
- package/src/webpack/common.ts +111 -0
- package/src/webpack/pilet.ts +121 -0
- package/src/webpack/piral.ts +110 -0
- package/src/webpack-hot-middleware/LICENSE +20 -0
- package/src/webpack-hot-middleware/client-overlay.js +99 -0
- package/src/webpack-hot-middleware/client.js +306 -0
- package/src/webpack-hot-middleware/helpers.js +9 -0
- package/src/webpack-hot-middleware/middleware.js +175 -0
- package/src/webpack-hot-middleware/process-update.js +157 -0
- package/lib/configs/HotModuleServerPlugin.js.map +0 -1
- package/lib/configs/SheetLoader.d.ts +0 -1
- package/lib/configs/SheetLoader.js +0 -27
- package/lib/configs/SheetLoader.js.map +0 -1
- package/lib/configs/common.d.ts +0 -6
- package/lib/configs/common.js +0 -115
- package/lib/configs/common.js.map +0 -1
- package/lib/configs/index.d.ts +0 -2
- package/lib/configs/index.js +0 -15
- package/lib/configs/index.js.map +0 -1
- package/lib/configs/pilet.d.ts +0 -3
- package/lib/configs/pilet.js +0 -72
- package/lib/configs/pilet.js.map +0 -1
- package/lib/configs/piral.d.ts +0 -2
- package/lib/configs/piral.js +0 -65
- package/lib/configs/piral.js.map +0 -1
- package/lib/webpack/bundler-calls.d.ts +0 -3
- package/lib/webpack/bundler-calls.js +0 -93
- package/lib/webpack/bundler-calls.js.map +0 -1
- package/lib/webpack/index.d.ts +0 -1
- package/lib/webpack/index.js +0 -14
- package/lib/webpack/index.js.map +0 -1
- package/lib/webpack/run-build-pilet.d.ts +0 -1
- package/lib/webpack/run-build-pilet.js +0 -53
- package/lib/webpack/run-build-pilet.js.map +0 -1
- package/lib/webpack/run-build-piral.d.ts +0 -1
- package/lib/webpack/run-build-piral.js +0 -56
- package/lib/webpack/run-build-piral.js.map +0 -1
- package/lib/webpack/run-debug-mono-piral.d.ts +0 -1
- package/lib/webpack/run-debug-mono-piral.js +0 -61
- package/lib/webpack/run-debug-mono-piral.js.map +0 -1
- package/lib/webpack/run-debug-pilet.d.ts +0 -1
- package/lib/webpack/run-debug-pilet.js +0 -77
- package/lib/webpack/run-debug-pilet.js.map +0 -1
- package/lib/webpack/run-debug-piral.d.ts +0 -1
- package/lib/webpack/run-debug-piral.js +0 -76
- package/lib/webpack/run-debug-piral.js.map +0 -1
- package/src/configs/SheetLoader.ts +0 -12
- package/src/configs/common.ts +0 -118
- package/src/configs/index.ts +0 -2
- package/src/configs/pilet.ts +0 -82
- package/src/configs/piral.ts +0 -73
- package/src/webpack/bundler-calls.ts +0 -107
- package/src/webpack/index.ts +0 -1
- package/src/webpack/run-build-pilet.ts +0 -82
- package/src/webpack/run-build-piral.ts +0 -83
- package/src/webpack/run-debug-mono-piral.ts +0 -76
- package/src/webpack/run-debug-pilet.ts +0 -94
- package/src/webpack/run-debug-piral.ts +0 -95
- /package/lib/{configs → enhancers/hmr-webpack-config-enhancer}/HotModuleServerPlugin.d.ts +0 -0
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import * as webpack from 'webpack';
|
|
2
2
|
import { resolve, basename, dirname } from 'path';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
|
-
import type { LogLevels } from 'piral-cli';
|
|
5
|
-
|
|
6
|
-
interface BuildResult {
|
|
7
|
-
outFile: string;
|
|
8
|
-
outDir: string;
|
|
9
|
-
}
|
|
4
|
+
import type { LogLevels, BundleHandlerResponse } from 'piral-cli';
|
|
10
5
|
|
|
11
6
|
function getOutput(stats: webpack.Stats) {
|
|
12
7
|
const { outputPath, entrypoints } = stats.toJson();
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
|
|
9
|
+
for (const name of Object.keys(entrypoints)) {
|
|
10
|
+
const assets = entrypoints[name].assets;
|
|
11
|
+
const firstAsset = assets.find((m) => m.name.endsWith('.js') || m.name.endsWith('.mjs'));
|
|
12
|
+
|
|
13
|
+
if (firstAsset) {
|
|
14
|
+
return resolve(outputPath, firstAsset.name);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
function getPreset(logLevel: LogLevels) {
|
|
@@ -31,77 +33,79 @@ function getPreset(logLevel: LogLevels) {
|
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
export function runWebpack(wpConfig: webpack.Configuration, logLevel: LogLevels) {
|
|
36
|
+
export function runWebpack(wpConfig: webpack.Configuration, logLevel: LogLevels): BundleHandlerResponse {
|
|
35
37
|
const eventEmitter = new EventEmitter();
|
|
36
38
|
const outDir = wpConfig.output.path;
|
|
37
|
-
const
|
|
39
|
+
const bundle = {
|
|
40
|
+
outFile: '',
|
|
41
|
+
outDir,
|
|
38
42
|
name: '',
|
|
43
|
+
hash: '',
|
|
39
44
|
requireRef: undefined,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const updateBundle = (stats: webpack.Stats) => {
|
|
48
|
+
const file = getOutput(stats);
|
|
49
|
+
bundle.name = basename(file);
|
|
50
|
+
bundle.requireRef = stats.compilation.outputOptions?.uniqueName;
|
|
51
|
+
bundle.hash = stats.hash;
|
|
52
|
+
bundle.outFile = `/${basename(file)}`;
|
|
53
|
+
bundle.outDir = dirname(file);
|
|
43
54
|
};
|
|
44
55
|
|
|
45
56
|
wpConfig.plugins.push({
|
|
46
57
|
apply(compiler: webpack.Compiler) {
|
|
47
58
|
compiler.hooks.beforeCompile.tap('piral-cli', () => {
|
|
48
|
-
eventEmitter.emit('
|
|
59
|
+
eventEmitter.emit('start');
|
|
49
60
|
});
|
|
50
61
|
|
|
51
62
|
compiler.hooks.done.tap('piral-cli', (stats) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
mainBundle.entryAsset.hash = stats.hash;
|
|
55
|
-
eventEmitter.emit('bundled');
|
|
63
|
+
updateBundle(stats);
|
|
64
|
+
eventEmitter.emit('end', bundle);
|
|
56
65
|
});
|
|
57
66
|
},
|
|
58
67
|
});
|
|
59
68
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const process = webpack(wpConfig, (err, stats) => {
|
|
67
|
-
if (err) {
|
|
68
|
-
console.error(err);
|
|
69
|
-
reject(err);
|
|
70
|
-
} else {
|
|
71
|
-
console.log(
|
|
72
|
-
stats.toString({
|
|
73
|
-
...preset.current,
|
|
74
|
-
colors: true,
|
|
75
|
-
}),
|
|
76
|
-
);
|
|
69
|
+
return {
|
|
70
|
+
bundle() {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
const preset = {
|
|
73
|
+
current: undefined,
|
|
74
|
+
};
|
|
77
75
|
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
const process = webpack(wpConfig, (err, stats) => {
|
|
77
|
+
if (err) {
|
|
78
|
+
console.error(err);
|
|
79
|
+
reject(err);
|
|
80
80
|
} else {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
console.log(
|
|
82
|
+
stats.toString({
|
|
83
|
+
...preset.current,
|
|
84
|
+
colors: true,
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
if (stats.hasErrors()) {
|
|
89
|
+
reject(stats.toJson(preset.current));
|
|
90
|
+
} else {
|
|
91
|
+
updateBundle(stats);
|
|
92
|
+
resolve(bundle);
|
|
93
|
+
}
|
|
86
94
|
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (process) {
|
|
98
|
+
// process is undefined in case of an error
|
|
99
|
+
const compilation = process.createCompilation();
|
|
100
|
+
preset.current = compilation.createStatsOptions(getPreset(logLevel));
|
|
87
101
|
}
|
|
88
102
|
});
|
|
89
|
-
|
|
90
|
-
const compilation = process.createCompilation();
|
|
91
|
-
preset.current = compilation.createStatsOptions(getPreset(logLevel));
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
bundle,
|
|
96
|
-
on(ev: string, listener: () => void) {
|
|
97
|
-
eventEmitter.on(ev, listener);
|
|
98
103
|
},
|
|
99
|
-
|
|
100
|
-
eventEmitter.
|
|
104
|
+
onStart(cb) {
|
|
105
|
+
eventEmitter.on('start', cb);
|
|
101
106
|
},
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
onEnd(cb) {
|
|
108
|
+
eventEmitter.on('end', cb);
|
|
104
109
|
},
|
|
105
|
-
mainBundle,
|
|
106
110
|
};
|
|
107
111
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
2
|
+
import { progress, logReset, log } from 'piral-cli/utils';
|
|
3
|
+
import { RuleSetRule, ProgressPlugin, WebpackPluginInstance, Configuration } from 'webpack';
|
|
4
|
+
|
|
5
|
+
const piletCss = 'main.css';
|
|
6
|
+
|
|
7
|
+
export function getStyleLoaders(useExtractLoader: boolean) {
|
|
8
|
+
if (useExtractLoader) {
|
|
9
|
+
return [MiniCssExtractPlugin.loader];
|
|
10
|
+
} else {
|
|
11
|
+
return [require.resolve('style-loader')];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type ConfigEnhancer = (config: Configuration) => Configuration;
|
|
16
|
+
|
|
17
|
+
export type DefaultConfiguration = [Configuration, ConfigEnhancer];
|
|
18
|
+
|
|
19
|
+
export const extensions = ['.ts', '.tsx', '.js', '.jsx', '.json'];
|
|
20
|
+
|
|
21
|
+
export function getVariables(): Record<string, string> {
|
|
22
|
+
return Object.keys(process.env).reduce((prev, curr) => {
|
|
23
|
+
prev[curr] = process.env[curr];
|
|
24
|
+
return prev;
|
|
25
|
+
}, {});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getPlugins(plugins: Array<WebpackPluginInstance>, pilet?: string) {
|
|
29
|
+
const otherPlugins: Array<WebpackPluginInstance> = [
|
|
30
|
+
new MiniCssExtractPlugin({
|
|
31
|
+
filename: pilet ? piletCss : '[name].[fullhash:6].css',
|
|
32
|
+
chunkFilename: '[id].[chunkhash:6].css',
|
|
33
|
+
}),
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
if (process.env.WEBPACK_PROGRESS) {
|
|
37
|
+
otherPlugins.push(
|
|
38
|
+
new ProgressPlugin((percent, msg) => {
|
|
39
|
+
if (percent !== undefined) {
|
|
40
|
+
progress(`${~~(percent * 100)}% : ${msg}`);
|
|
41
|
+
|
|
42
|
+
if (percent === 1) {
|
|
43
|
+
logReset();
|
|
44
|
+
log('generalInfo_0000', 'Bundling finished.');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return plugins.concat(otherPlugins);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function getRules(styleLoaders: Array<string>): Array<RuleSetRule> {
|
|
55
|
+
const nodeModules = /node_modules/;
|
|
56
|
+
const babelLoader = {
|
|
57
|
+
loader: require.resolve('babel-loader'),
|
|
58
|
+
options: {
|
|
59
|
+
presets: [require.resolve('@babel/preset-env'), require.resolve('@babel/preset-react')],
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const tsLoader = {
|
|
63
|
+
loader: require.resolve('ts-loader'),
|
|
64
|
+
options: {
|
|
65
|
+
transpileOnly: true,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
oneOf: [
|
|
72
|
+
{
|
|
73
|
+
test: /\.s[ac]ss$/i,
|
|
74
|
+
use: [...styleLoaders, require.resolve('css-loader'), require.resolve('sass-loader')],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
test: /\.css$/i,
|
|
78
|
+
use: [...styleLoaders, require.resolve('css-loader')],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
test: /\.m?jsx?$/i,
|
|
82
|
+
use: [babelLoader],
|
|
83
|
+
exclude: nodeModules,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
test: /\.tsx?$/i,
|
|
87
|
+
use: [babelLoader, tsLoader],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
test: /\.codegen$/i,
|
|
91
|
+
use: [require.resolve('parcel-codegen-loader')],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
test: /\.js$/i,
|
|
95
|
+
use: [require.resolve('source-map-loader')],
|
|
96
|
+
exclude: nodeModules,
|
|
97
|
+
enforce: 'pre',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
// Exclude `js` files to keep "css" loader working as it injects
|
|
101
|
+
// its runtime that would otherwise be processed through "file" loader.
|
|
102
|
+
// Also exclude `html` and `json` extensions so they get processed
|
|
103
|
+
// by webpacks internal loaders.
|
|
104
|
+
exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx|vue|svelte|elm)$/i, /\.html$/i, /\.json$/i],
|
|
105
|
+
type: 'asset/resource',
|
|
106
|
+
},
|
|
107
|
+
// Don't add new loaders here -> should be added before the last (catch-all) handler
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { PiletBuildHandler } from 'piral-cli';
|
|
2
|
+
import * as TerserPlugin from 'terser-webpack-plugin';
|
|
3
|
+
import * as CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
4
|
+
import type { PiletSchemaVersion, SharedDependency } from 'piral-cli';
|
|
5
|
+
import { getRules, getPlugins, extensions, getVariables, DefaultConfiguration, getStyleLoaders } from './common';
|
|
6
|
+
import { piletWebpackConfigEnhancer } from '../enhancers/pilet-webpack-config-enhancer';
|
|
7
|
+
import { resolve } from 'path';
|
|
8
|
+
import { runWebpack } from './bundler-run';
|
|
9
|
+
import { defaultWebpackConfig } from '../constants';
|
|
10
|
+
import { extendConfig } from '../helpers';
|
|
11
|
+
|
|
12
|
+
async function getConfig(
|
|
13
|
+
template: string,
|
|
14
|
+
dist: string,
|
|
15
|
+
filename: string,
|
|
16
|
+
externals: Array<string>,
|
|
17
|
+
importmap: Array<SharedDependency> = [],
|
|
18
|
+
piralInstances: Array<string>,
|
|
19
|
+
schema: PiletSchemaVersion,
|
|
20
|
+
develop = false,
|
|
21
|
+
sourceMaps = true,
|
|
22
|
+
contentHash = true,
|
|
23
|
+
minimize = true,
|
|
24
|
+
): Promise<DefaultConfiguration> {
|
|
25
|
+
const production = !develop;
|
|
26
|
+
const name = process.env.BUILD_PCKG_NAME;
|
|
27
|
+
const version = process.env.BUILD_PCKG_VERSION;
|
|
28
|
+
const entry = filename.replace(/\.js$/i, '');
|
|
29
|
+
|
|
30
|
+
const enhance = piletWebpackConfigEnhancer({
|
|
31
|
+
name,
|
|
32
|
+
piralInstances,
|
|
33
|
+
version,
|
|
34
|
+
entry,
|
|
35
|
+
externals,
|
|
36
|
+
importmap,
|
|
37
|
+
schema,
|
|
38
|
+
filename,
|
|
39
|
+
variables: getVariables(),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const styleLoaders = getStyleLoaders(true);
|
|
43
|
+
|
|
44
|
+
return [
|
|
45
|
+
{
|
|
46
|
+
devtool: sourceMaps ? (develop ? 'cheap-module-source-map' : 'source-map') : false,
|
|
47
|
+
|
|
48
|
+
mode: develop ? 'development' : 'production',
|
|
49
|
+
|
|
50
|
+
target: 'web',
|
|
51
|
+
|
|
52
|
+
entry: {
|
|
53
|
+
[entry]: [template],
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
output: {
|
|
57
|
+
publicPath: './',
|
|
58
|
+
path: dist,
|
|
59
|
+
filename: '[name].js',
|
|
60
|
+
chunkFilename: contentHash ? '[chunkhash:8].js' : undefined,
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
resolve: {
|
|
64
|
+
extensions,
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
module: {
|
|
68
|
+
rules: getRules(styleLoaders),
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
optimization: {
|
|
72
|
+
minimize,
|
|
73
|
+
minimizer: [
|
|
74
|
+
new TerserPlugin({
|
|
75
|
+
extractComments: false,
|
|
76
|
+
terserOptions: {
|
|
77
|
+
ie8: true,
|
|
78
|
+
output: {
|
|
79
|
+
comments: /^@pilet/,
|
|
80
|
+
},
|
|
81
|
+
mangle: {
|
|
82
|
+
reserved: ['__bundleUrl__'],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
new CssMinimizerPlugin(),
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
plugins: getPlugins([], entry),
|
|
91
|
+
},
|
|
92
|
+
enhance,
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const handler: PiletBuildHandler = {
|
|
97
|
+
async create(options) {
|
|
98
|
+
const { config = defaultWebpackConfig } = options.args._;
|
|
99
|
+
const otherConfigPath = resolve(options.root, config);
|
|
100
|
+
const baseConfig = await getConfig(
|
|
101
|
+
options.entryModule,
|
|
102
|
+
options.outDir,
|
|
103
|
+
options.outFile,
|
|
104
|
+
options.externals,
|
|
105
|
+
options.importmap,
|
|
106
|
+
options.piralInstances,
|
|
107
|
+
options.version,
|
|
108
|
+
options.develop,
|
|
109
|
+
options.sourceMaps,
|
|
110
|
+
options.contentHash,
|
|
111
|
+
options.minify,
|
|
112
|
+
);
|
|
113
|
+
const wpConfig = extendConfig(baseConfig, otherConfigPath, {
|
|
114
|
+
watch: options.watch,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return runWebpack(wpConfig, options.logLevel);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const create = handler.create;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { PiralBuildHandler } from 'piral-cli';
|
|
2
|
+
import * as webpack from 'webpack';
|
|
3
|
+
import * as TerserPlugin from 'terser-webpack-plugin';
|
|
4
|
+
import * as CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
5
|
+
import { getFreePort } from 'piral-cli/utils';
|
|
6
|
+
import { resolve } from 'path';
|
|
7
|
+
import { runWebpack } from './bundler-run';
|
|
8
|
+
import { getRules, getPlugins, extensions, getVariables, DefaultConfiguration, getStyleLoaders } from './common';
|
|
9
|
+
import { html5EntryWebpackConfigEnhancer } from '../enhancers/html5-entry-webpack-config-enhancer';
|
|
10
|
+
import { piralInstanceWebpackConfigEnhancer } from '../enhancers/piral-instance-webpack-config-enhancer';
|
|
11
|
+
import { hmrWebpackConfigEnhancer } from '../enhancers/hmr-webpack-config-enhancer';
|
|
12
|
+
import { defaultWebpackConfig } from '../constants';
|
|
13
|
+
import { extendConfig } from '../helpers';
|
|
14
|
+
|
|
15
|
+
async function getConfig(
|
|
16
|
+
template: string,
|
|
17
|
+
dist: string,
|
|
18
|
+
externals: Array<string>,
|
|
19
|
+
develop = false,
|
|
20
|
+
sourceMaps = true,
|
|
21
|
+
contentHash = true,
|
|
22
|
+
minimize = true,
|
|
23
|
+
publicPath = '/',
|
|
24
|
+
hmr = 0,
|
|
25
|
+
): Promise<DefaultConfiguration> {
|
|
26
|
+
const production = !develop;
|
|
27
|
+
const name = process.env.BUILD_PCKG_NAME;
|
|
28
|
+
const version = process.env.BUILD_PCKG_VERSION;
|
|
29
|
+
|
|
30
|
+
const enhance = (options: webpack.Configuration) =>
|
|
31
|
+
[
|
|
32
|
+
hmrWebpackConfigEnhancer({ port: hmr }),
|
|
33
|
+
html5EntryWebpackConfigEnhancer({}),
|
|
34
|
+
piralInstanceWebpackConfigEnhancer({
|
|
35
|
+
name,
|
|
36
|
+
version,
|
|
37
|
+
externals,
|
|
38
|
+
variables: getVariables(),
|
|
39
|
+
}),
|
|
40
|
+
].reduceRight((acc, val) => val(acc), options);
|
|
41
|
+
|
|
42
|
+
const styleLoaders = getStyleLoaders(production);
|
|
43
|
+
|
|
44
|
+
return [
|
|
45
|
+
{
|
|
46
|
+
devtool: sourceMaps ? (develop ? 'cheap-module-source-map' : 'source-map') : false,
|
|
47
|
+
|
|
48
|
+
mode: develop ? 'development' : 'production',
|
|
49
|
+
|
|
50
|
+
entry: [template],
|
|
51
|
+
|
|
52
|
+
output: {
|
|
53
|
+
publicPath,
|
|
54
|
+
path: dist,
|
|
55
|
+
filename: `index.${contentHash ? '[contenthash:6].' : ''}js`,
|
|
56
|
+
chunkFilename: contentHash ? '[chunkhash:6].js' : undefined,
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
resolve: {
|
|
60
|
+
extensions,
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
module: {
|
|
64
|
+
rules: getRules(styleLoaders),
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
optimization: {
|
|
68
|
+
minimize,
|
|
69
|
+
minimizer: [
|
|
70
|
+
new TerserPlugin({
|
|
71
|
+
extractComments: false,
|
|
72
|
+
terserOptions: {
|
|
73
|
+
ie8: true,
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
new CssMinimizerPlugin(),
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
plugins: getPlugins([]),
|
|
81
|
+
},
|
|
82
|
+
enhance,
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const handler: PiralBuildHandler = {
|
|
87
|
+
async create(options) {
|
|
88
|
+
const { 'hmr-port': defaultHmrPort = 62123, config = defaultWebpackConfig } = options.args._;
|
|
89
|
+
const hmrPort = options.hmr ? await getFreePort(defaultHmrPort) : 0;
|
|
90
|
+
const otherConfigPath = resolve(options.root, config);
|
|
91
|
+
const baseConfig = await getConfig(
|
|
92
|
+
options.entryFiles,
|
|
93
|
+
options.outDir,
|
|
94
|
+
options.externals,
|
|
95
|
+
options.emulator,
|
|
96
|
+
options.sourceMaps,
|
|
97
|
+
options.contentHash,
|
|
98
|
+
options.minify,
|
|
99
|
+
options.publicUrl,
|
|
100
|
+
hmrPort,
|
|
101
|
+
);
|
|
102
|
+
const wpConfig = extendConfig(baseConfig, otherConfigPath, {
|
|
103
|
+
watch: options.watch,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return runWebpack(wpConfig, options.logLevel);
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const create = handler.create;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright JS Foundation and other contributors
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*eslint-env browser*/
|
|
2
|
+
|
|
3
|
+
var clientOverlay = document.createElement('div');
|
|
4
|
+
clientOverlay.id = 'webpack-hot-middleware-clientOverlay';
|
|
5
|
+
var styles = {
|
|
6
|
+
background: 'rgba(0,0,0,0.85)',
|
|
7
|
+
color: '#e8e8e8',
|
|
8
|
+
lineHeight: '1.6',
|
|
9
|
+
whiteSpace: 'pre',
|
|
10
|
+
fontFamily: 'Menlo, Consolas, monospace',
|
|
11
|
+
fontSize: '13px',
|
|
12
|
+
position: 'fixed',
|
|
13
|
+
zIndex: 9999,
|
|
14
|
+
padding: '10px',
|
|
15
|
+
left: 0,
|
|
16
|
+
right: 0,
|
|
17
|
+
top: 0,
|
|
18
|
+
bottom: 0,
|
|
19
|
+
overflow: 'auto',
|
|
20
|
+
dir: 'ltr',
|
|
21
|
+
textAlign: 'left',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var ansiHTML = require('ansi-html-community');
|
|
25
|
+
var colors = {
|
|
26
|
+
reset: ['transparent', 'transparent'],
|
|
27
|
+
black: '181818',
|
|
28
|
+
red: 'ff3348',
|
|
29
|
+
green: '3fff4f',
|
|
30
|
+
yellow: 'ffd30e',
|
|
31
|
+
blue: '169be0',
|
|
32
|
+
magenta: 'f840b7',
|
|
33
|
+
cyan: '0ad8e9',
|
|
34
|
+
lightgrey: 'ebe7e3',
|
|
35
|
+
darkgrey: '6d7891',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
var Entities = require('html-entities').AllHtmlEntities;
|
|
39
|
+
var entities = new Entities();
|
|
40
|
+
|
|
41
|
+
function showProblems(type, lines) {
|
|
42
|
+
clientOverlay.innerHTML = '';
|
|
43
|
+
lines.forEach(function(msg) {
|
|
44
|
+
msg = ansiHTML(entities.encode(msg));
|
|
45
|
+
var div = document.createElement('div');
|
|
46
|
+
div.style.marginBottom = '26px';
|
|
47
|
+
div.innerHTML = problemType(type) + ' in ' + msg;
|
|
48
|
+
clientOverlay.appendChild(div);
|
|
49
|
+
});
|
|
50
|
+
if (document.body) {
|
|
51
|
+
document.body.appendChild(clientOverlay);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function clear() {
|
|
56
|
+
if (document.body && clientOverlay.parentNode) {
|
|
57
|
+
document.body.removeChild(clientOverlay);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function problemType(type) {
|
|
62
|
+
var problemColors = {
|
|
63
|
+
errors: colors.red,
|
|
64
|
+
warnings: colors.yellow,
|
|
65
|
+
};
|
|
66
|
+
var color = problemColors[type] || colors.red;
|
|
67
|
+
return (
|
|
68
|
+
'<span style="background-color:#' +
|
|
69
|
+
color +
|
|
70
|
+
'; color:#000000; padding:3px 6px; border-radius: 4px;">' +
|
|
71
|
+
type.slice(0, -1).toUpperCase() +
|
|
72
|
+
'</span>'
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = function(options) {
|
|
77
|
+
for (var color in options.ansiColors) {
|
|
78
|
+
if (color in colors) {
|
|
79
|
+
colors[color] = options.ansiColors[color];
|
|
80
|
+
}
|
|
81
|
+
ansiHTML.setColors(colors);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
for (var style in options.overlayStyles) {
|
|
85
|
+
styles[style] = options.overlayStyles[style];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (var key in styles) {
|
|
89
|
+
clientOverlay.style[key] = styles[key];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
showProblems: showProblems,
|
|
94
|
+
clear: clear,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
module.exports.clear = clear;
|
|
99
|
+
module.exports.showProblems = showProblems;
|