@lls/vitescripts 1.1.0 → 1.1.2
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/package.json
CHANGED
package/src/llsAssetsPlugin.mjs
CHANGED
|
@@ -5,6 +5,13 @@ import path from 'path'
|
|
|
5
5
|
const execP = promisify(exec)
|
|
6
6
|
|
|
7
7
|
// https://github.com/vitejs/vite/pull/8574
|
|
8
|
+
/**
|
|
9
|
+
* Plugin that will copy assets from given repos to public dir of launched project
|
|
10
|
+
* @param {*} llsRepos array containing names of the repos
|
|
11
|
+
* @param {*} publicDir public dir to copy assets to
|
|
12
|
+
* @returns config() method that copies assets
|
|
13
|
+
* transform() method that replaces assets path to be resolved
|
|
14
|
+
*/
|
|
8
15
|
const llsAssetsPlugin = (llsRepos, publicDir = 'ladleassets') => {
|
|
9
16
|
const publicAssetDir = path.join(publicDir, 'assets')
|
|
10
17
|
const fileExists = (s) => new Promise(resolve => fs.access(s, e => resolve(!e)))
|
|
@@ -12,7 +19,7 @@ const llsAssetsPlugin = (llsRepos, publicDir = 'ladleassets') => {
|
|
|
12
19
|
const storyRoot = process.cwd() + '/stories'
|
|
13
20
|
return {
|
|
14
21
|
name: 'lls:copyassets',
|
|
15
|
-
async config(
|
|
22
|
+
async config() {
|
|
16
23
|
await execP(`mkdir -p ${publicAssetDir}`)
|
|
17
24
|
const repoArgs = await Promise.all(llsRepos.map(async repo => {
|
|
18
25
|
if (!repo.startsWith('@')) return repo
|
|
@@ -1,17 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin that collects styles from linaria cache to inject it in the page.
|
|
3
|
+
* @returns config() method that instantiates linariaPlugin
|
|
4
|
+
* resolveId() method that filters files to be added to css set
|
|
5
|
+
* flushStyles() method that generates and return <style> tag with refreshed style
|
|
6
|
+
*/
|
|
1
7
|
const llsLinariaSsrCollectPlugin = () => {
|
|
2
8
|
const cssIds = new Set()
|
|
3
9
|
let linariaPlugin
|
|
4
10
|
return {
|
|
5
11
|
name: 'lls:llsLinariaSsrCollect',
|
|
12
|
+
/* we enforce pre because if vite-plugin-linaria resolves id, vite4 won't call us. Since we do not resolve, we can be put before */
|
|
13
|
+
enforce: 'pre',
|
|
6
14
|
config(config) {
|
|
7
15
|
linariaPlugin = config.plugins.find(plugin => plugin.name === 'linaria')
|
|
8
16
|
},
|
|
9
17
|
async resolveId(id, from) {
|
|
10
18
|
if (id.includes('@linaria-cache')) { cssIds.add(id) }
|
|
11
19
|
},
|
|
20
|
+
flushStyles() {
|
|
21
|
+
const back = `<style id="linaria-ssr-collect-plugin">${[...cssIds].map(linariaPlugin.load).join('\n')}</style>`
|
|
22
|
+
// linaria plugin keeps cache. But we dont want to keep ids which have changed (updating a css component)
|
|
23
|
+
// css is removed from client anyway but still be accurate
|
|
24
|
+
cssIds.clear()
|
|
12
25
|
|
|
13
|
-
|
|
14
|
-
return `<style>${[...cssIds].map(linariaPlugin.load).join('\n')}</style>`
|
|
26
|
+
return back
|
|
15
27
|
}
|
|
16
28
|
}
|
|
17
29
|
}
|
package/src/llsRequirePlugin.mjs
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import VitePluginRequireTransform from 'vite-plugin-require-transform'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Plugin using vite-plugin-require-transform, used to transform require syntax to import
|
|
5
|
+
* Needed when we use viewer in sideRefresh
|
|
6
|
+
* @returns the plugin with its transform method
|
|
7
|
+
*/
|
|
4
8
|
const llsSsrRequirePlugin = () => {
|
|
9
|
+
// Lazy loaded viewer modules that are using require syntax
|
|
5
10
|
const fileRegex = /(?:(Audio|Recorder|Python|Video|QuestionRich|CodemirrorEditor|useLazyModule)\.jsx$|@lls_lls-code)/
|
|
6
11
|
const back = VitePluginRequireTransform({ fileRegex })
|
|
7
12
|
return {
|
|
@@ -19,4 +24,4 @@ const llsSsrRequirePlugin = () => {
|
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
export default llsSsrRequirePlugin
|
|
27
|
+
export default llsSsrRequirePlugin
|
|
@@ -9,6 +9,7 @@ const pwd = process.cwd()
|
|
|
9
9
|
*/
|
|
10
10
|
const llsSideRefreshMetaPlugin = ({ viewer: iViewer, superkit: iSuperkit, kit: iKit, utils: iUtils }) => {
|
|
11
11
|
if (!iViewer && !iSuperkit && !iKit && !iUtils) { return { plugin: () => false, alias: {} } }
|
|
12
|
+
// eslint-disable-next-line no-console
|
|
12
13
|
console.log('sideResfresh: ', [
|
|
13
14
|
iViewer && 'viewer',
|
|
14
15
|
iSuperkit && 'superkit',
|