-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webpack-extensions): add ability to generate css vars named expo…
…rts in manifest index (3.x) (#2119)
- Loading branch information
Showing
7 changed files
with
145 additions
and
35 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
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
61 changes: 61 additions & 0 deletions
61
packages/webpack-extensions/test/e2e/manifest.css-vars.spec.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,61 @@ | ||
import { StylableProjectRunner } from '@stylable/e2e-test-kit'; | ||
import { expect } from 'chai'; | ||
import { readFileSync } from 'fs'; | ||
import { dirname, join } from 'path'; | ||
import { hashContent } from '@stylable/webpack-extensions'; | ||
import { EOL } from 'os'; | ||
|
||
const project = 'manifest-plugin'; | ||
const projectDir = dirname( | ||
require.resolve(`@stylable/webpack-extensions/test/e2e/projects/${project}/webpack.config`) | ||
); | ||
|
||
describe(`${project} - manifest`, () => { | ||
const projectRunner = StylableProjectRunner.mochaSetup( | ||
{ | ||
projectDir, | ||
launchOptions: { | ||
// headless: false | ||
}, | ||
configName: 'webpack.css-vars.config', | ||
}, | ||
before, | ||
afterEach, | ||
after | ||
); | ||
|
||
it('Should generate manifest for the current build', () => { | ||
const assets = projectRunner.getBuildAssets(); | ||
const manifestKey = Object.keys(assets).find((key) => key.startsWith('stylable.manifest'))!; | ||
const source = assets[manifestKey].source(); | ||
|
||
const compContent = readFileSync( | ||
join(projectRunner.projectDir, 'Button.comp.st.css'), | ||
'utf-8' | ||
); | ||
const commonContent = readFileSync( | ||
join(projectRunner.projectDir, 'common.st.css'), | ||
'utf-8' | ||
); | ||
const commonHash = hashContent(commonContent); | ||
const compHash = hashContent(compContent); | ||
|
||
expect(JSON.parse(source)).to.deep.include({ | ||
name: 'manifest-plugin-test', | ||
version: '0.0.0-test', | ||
componentsIndex: `:import{-st-from: "/${compHash}.st.css";-st-default: Button;-st-named:--myColor as --Button-myColor;} Button{}${EOL}`, | ||
componentsEntries: { Button: `/${compHash}.st.css` }, | ||
stylesheetMapping: { | ||
[`/${compHash}.st.css`]: compContent.replace( | ||
'./common.st.css', | ||
`/${commonHash}.st.css` | ||
), | ||
[`/${commonHash}.st.css`]: commonContent, | ||
}, | ||
namespaceMapping: { | ||
[`/${commonHash}.st.css`]: 'common911354609', | ||
[`/${compHash}.st.css`]: 'Buttoncomp1090430236', | ||
}, | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
} | ||
|
||
.root { | ||
--myColor: red; | ||
color: value(myColor) | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/webpack-extensions/test/e2e/projects/manifest-plugin/webpack.css-vars.config.js
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,27 @@ | ||
const { stylableLoaders } = require('@stylable/experimental-loader'); | ||
const { StylableManifestPlugin } = require('@stylable/webpack-extensions'); | ||
|
||
/** @type {import('webpack').Configuration} */ | ||
module.exports = { | ||
mode: 'development', | ||
context: __dirname, | ||
devtool: 'source-map', | ||
entry: require.resolve('./index'), | ||
output: { | ||
library: 'metadata', | ||
}, | ||
plugins: [ | ||
new StylableManifestPlugin({ | ||
package: require('./package.json'), | ||
generateCSSVarsExports: true, | ||
}), | ||
], | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.st\.css?$/, | ||
use: [stylableLoaders.transform({ exportsOnly: true })], | ||
}, | ||
], | ||
}, | ||
}; |