sails-hook-shipwright 0.1.2 → 0.2.0

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/index.js CHANGED
@@ -8,13 +8,49 @@
8
8
  const path = require('path')
9
9
  const { defineConfig, mergeRsbuildConfig } = require('@rsbuild/core')
10
10
  module.exports = function defineShipwrightHook(sails) {
11
+ function getManifestFiles() {
12
+ const manifestPath = path.resolve(
13
+ sails.config.appPath,
14
+ '.tmp',
15
+ 'public',
16
+ 'manifest.json'
17
+ )
18
+ const data = require(manifestPath)
19
+ const files = data.allFiles
20
+ return files
21
+ }
22
+ function generateScripts() {
23
+ const manifestFiles = getManifestFiles()
24
+ let scripts = []
25
+ manifestFiles.forEach((file) => {
26
+ if (file.endsWith('.js')) {
27
+ scripts.push(`<script type="text/javascript" src="${file}"></script>`)
28
+ }
29
+ })
30
+ return scripts.join('\n')
31
+ }
32
+
33
+ function generateStyles() {
34
+ const manifestFiles = getManifestFiles()
35
+ let styles = []
36
+ manifestFiles.forEach((file) => {
37
+ if (file.endsWith('.css')) {
38
+ styles.push(`<link rel="stylesheet" href="${file}">`)
39
+ }
40
+ })
41
+ return styles.join('\n')
42
+ }
11
43
  return {
44
+ defaults: {
45
+ shipwright: {
46
+ build: {}
47
+ }
48
+ },
12
49
  /**
13
50
  * Runs when this Sails app loads/lifts.
14
51
  */
15
52
  initialize: async function () {
16
53
  const appPath = sails.config.appPath
17
-
18
54
  const defaultConfigs = defineConfig({
19
55
  source: {
20
56
  entry: {
@@ -26,7 +62,7 @@ module.exports = function defineShipwrightHook(sails) {
26
62
  }
27
63
  },
28
64
  output: {
29
- filenameHash: false,
65
+ manifest: true,
30
66
  distPath: {
31
67
  root: '.tmp/public',
32
68
  css: 'css',
@@ -64,13 +100,16 @@ module.exports = function defineShipwrightHook(sails) {
64
100
  },
65
101
  performance: {
66
102
  chunkSplit: {
67
- strategy: 'all-in-one'
103
+ strategy: 'split-by-experience'
68
104
  }
69
105
  },
70
106
  server: {
71
107
  port: sails.config.port,
72
108
  strictPort: true,
73
109
  printUrls: false
110
+ },
111
+ dev: {
112
+ writeToDisk: (file) => file.includes('manifest.json') // Write manifest file
74
113
  }
75
114
  })
76
115
  const config = mergeRsbuildConfig(
@@ -80,8 +119,8 @@ module.exports = function defineShipwrightHook(sails) {
80
119
  const { createRsbuild } = require('@rsbuild/core')
81
120
  try {
82
121
  const rsbuild = await createRsbuild({ rsbuildConfig: config })
83
- if (process.env.NODE_ENV == 'production') {
84
- rsbuild.build()
122
+ if (process.env.NODE_ENV === 'production') {
123
+ await rsbuild.build()
85
124
  } else {
86
125
  const rsbuildDevServer = await rsbuild.createDevServer()
87
126
  sails.after('hook:http:loaded', async () => {
@@ -97,9 +136,13 @@ module.exports = function defineShipwrightHook(sails) {
97
136
  sails.on('lower', async () => {
98
137
  await rsbuildDevServer.close()
99
138
  })
139
+ sails.after('lifted', () => {})
140
+ }
141
+ sails.config.views.locals = {
142
+ shipwright: { scripts: generateScripts, styles: generateStyles }
100
143
  }
101
144
  } catch (error) {
102
- sails.error(error)
145
+ sails.log.error(error)
103
146
  }
104
147
  }
105
148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sails-hook-shipwright",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "The modern asset pipeline for Sails",
5
5
  "main": "index.js",
6
6
  "scripts": {
Binary file