-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
130 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/tooling/piral-cli-webpack5/src/plugins/StylesLoader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { getOptions } from 'loader-utils'; | ||
|
||
export default function stylesLoader() { | ||
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(';'); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/tooling/piral-cli-webpack5/src/plugins/StylesPlugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { resolve } from 'path'; | ||
import { Compilation } from 'webpack'; | ||
import { RawSource } from 'webpack-sources'; | ||
|
||
export default class StylesPlugin { | ||
constructor(private cssName: string, private entryName: string) {} | ||
|
||
apply(compiler) { | ||
const { entry } = compiler.options; | ||
|
||
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) { | ||
compilation.hooks.processAssets.tap( | ||
{ | ||
name: 'StylesPlugin', | ||
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS, | ||
}, | ||
(assets) => { | ||
if (!assets[this.cssName]) { | ||
const source = new RawSource(''); | ||
compilation.emitAsset(this.cssName, source); | ||
} | ||
}, | ||
); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters