Skip to content

Commit

Permalink
Fixes for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Apr 28, 2023
1 parent 68c6dc6 commit 3ee67d0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,14 @@ function piletV3WebpackConfigEnhancer(options: SchemaEnhancerOptions, compiler:
include: file,
raw: true,
}),
new SystemJSPublicPathWebpackPlugin(),
);

compiler.output.publicPath = '';
compiler.output.chunkFormat = 'module';
compiler.plugins = [...compiler.plugins, ...plugins];
compiler.output.uniqueName = `${jsonpFunction}`;
compiler.output.library = { type: 'system' };
compiler.target = 'node';

return compiler;
}
Expand Down
3 changes: 2 additions & 1 deletion src/tooling/piral-cli-webpack5/src/plugins/StylesLoader.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { getOptions } from 'loader-utils';

export default function stylesLoader() {
const { cssName } = getOptions(this);
const { cssName, entries } = getOptions(this);
const debug = process.env.NODE_ENV === 'development';
return [
`const u = ${JSON.stringify(cssName)}`,
`export const styles = [${debug ? 'u+"?_="+Math.random()' : 'u'}]`,
...entries.split(',').map((entry) => `export * from ${JSON.stringify(entry)}`),
].join(';');
}
13 changes: 7 additions & 6 deletions src/tooling/piral-cli-webpack5/src/plugins/StylesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { Compilation } from 'webpack';
import { RawSource } from 'webpack-sources';

export default class StylesPlugin {
private loaderPath: string;

constructor(private cssName: string, private entryName: string) {
this.loaderPath = resolve(__dirname, `StylesLoader?cssName=${cssName}!`);
}
constructor(private cssName: string, private entryName: string) {}

apply(compiler) {
const { entry } = compiler.options;

entry[this.entryName].import = [this.loaderPath, ...entry[this.entryName].import];
const entries = entry[this.entryName].import;
const query = `cssName=${this.cssName}&entries=${entries.join(',')}!`;
const setPath = resolve(__dirname, '..', 'set-path');
const loaderPath = resolve(__dirname, `StylesLoader?${query}`);

entry[this.entryName].import = [setPath, loaderPath];

compiler.hooks.compilation.tap('StylesPlugin', (compilation: Compilation) => {
if (!compilation.compiler.parentCompilation) {
Expand Down
7 changes: 5 additions & 2 deletions src/tooling/piral-cli-webpack5/src/webpack/bundler-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ function getOutput(stats: webpack.Stats) {

for (const name of Object.keys(entrypoints)) {
const assets = entrypoints[name].assets;
const firstAsset = assets[0];
return resolve(outputPath, firstAsset.name);
const firstAsset = assets.find((m) => m.name.endsWith('.js') || m.name.endsWith('.mjs'));

if (firstAsset) {
return resolve(outputPath, firstAsset.name);
}
}
}

Expand Down

0 comments on commit 3ee67d0

Please sign in to comment.