@imtf/profile-scripts 1.0.2 → 1.0.6

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.
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const spawn = require('cross-spawn')
4
3
  const concurrently = require('concurrently')
4
+ const spawn = require('cross-spawn')
5
5
 
6
6
  const args = process.argv.slice(2)
7
- const scriptIndex = args.findIndex((x) => x === 'build' || x === 'start')
7
+ const scriptIndex = args.findIndex(x => x === 'build' || x === 'start')
8
8
  const script = scriptIndex === -1 ? args[0] : args[scriptIndex]
9
9
 
10
10
  const scriptPath = require.resolve(`../scripts/esbuild.mjs`)
package/changelog.md ADDED
@@ -0,0 +1,42 @@
1
+ # Versions
2
+
3
+ Here you can find a resume of all changes between versions.
4
+
5
+ ## 1.0.6
6
+
7
+ ### Features
8
+
9
+ - Load css (.css) as text (they are no longer built in a separate .css files)
10
+
11
+ ## 1.0.5
12
+
13
+ ### Bug fixes
14
+
15
+ - Npm package issues fixed.
16
+
17
+ ## 1.0.4
18
+
19
+ ### Features
20
+
21
+ - Use differents loaders for svgs :
22
+ * Svgs part of /src except ones that are in /src/assets will be
23
+ loaded as React components with svgr.
24
+ * Others will be loaded as dataurl (base64)
25
+
26
+ ## 1.0.3
27
+
28
+ ### Features
29
+
30
+ - Load fonts (.ttf, .eot) and images (.gif, .svg) within js file as data-urls
31
+
32
+ ## 1.0.2
33
+
34
+ ### Features
35
+
36
+ - Load fonts (.woff, .woff2) and images (.jpg, .png) within js file as data-urls
37
+
38
+ ## 1.0.1
39
+
40
+ ### Bug fixes
41
+
42
+ - Moved some dependencies from devDepenencies to dependencies.
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@imtf/profile-scripts",
3
- "version": "1.0.2",
3
+ "version": "1.0.6",
4
4
  "description": "Default scripts to bundle & transpile imtf front-end plugins",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "profile-scripts": "./bin/profile-scripts.js"
8
8
  },
9
9
  "files": [
10
- "scripts/esbuild.mjs",
11
- ".prettierrc.js",
12
- "yarn.lock"
10
+ "bin/",
11
+ "scripts/",
12
+ "changelog.md"
13
13
  ],
14
14
  "scripts": {
15
15
  "build": "NODE_ENV=production node scripts/esbuild.mjs",
@@ -25,14 +25,14 @@
25
25
  "license": "UNLICENSED",
26
26
  "private": false,
27
27
  "dependencies": {
28
+ "@svgr/core": "^6.2.0",
28
29
  "concurrently": "^6.2.1",
29
30
  "esbuild": "^0.14.8",
30
31
  "esbuild-plugin-external-global": "^1.0.1",
31
- "esbuild-plugin-svgr": "^1.0.0",
32
32
  "serve": "^13.0.2"
33
33
  },
34
34
  "devDependencies": {
35
- "@imtf/prettier-config": "^1.0.0",
36
- "@imtf/eslint-config-react": "^1.0.0"
35
+ "@imtf/eslint-config-react": "^1.0.0",
36
+ "@imtf/prettier-config": "^1.0.0"
37
37
  }
38
38
  }
@@ -1,8 +1,9 @@
1
1
  import { build } from 'esbuild'
2
- import svgrPlugin from 'esbuild-plugin-svgr'
3
2
  import externalGlobalPlugin from 'esbuild-plugin-external-global'
4
3
  import minimist from 'minimist'
5
4
 
5
+ import svgPlugin from './svgPlugin.mjs'
6
+
6
7
  const { watch } = minimist(process.argv.slice(2))
7
8
 
8
9
  build({
@@ -25,19 +26,22 @@ build({
25
26
  minify:
26
27
  process.env.NODE_ENV === 'production' &&
27
28
  process.env.IMTF_MINIFY_WEBAPP !== 'false',
28
- // jsx: 'transform',
29
29
  loader: {
30
30
  // Enable JSX in .js files too
31
+ '.css': 'text',
31
32
  '.js': 'jsx',
32
33
  // Embed fonts
34
+ '.eot': 'dataurl',
35
+ '.ttf': 'dataurl',
33
36
  '.woff': 'dataurl',
34
37
  '.woff2': 'dataurl',
35
38
  // Embed images
39
+ '.gif': 'dataurl',
36
40
  '.jpg': 'dataurl',
37
41
  '.png': 'dataurl',
38
42
  },
39
43
  plugins: [
40
- svgrPlugin(),
44
+ svgPlugin(),
41
45
  externalGlobalPlugin.externalGlobalPlugin({
42
46
  react: 'window.React',
43
47
  'react-dom': 'window.ReactDOM',
@@ -0,0 +1,40 @@
1
+ import { transform } from '@svgr/core'
2
+ import fs from 'fs'
3
+ import path from 'path'
4
+
5
+ const svgPlugin = (options = {}) => ({
6
+ name: 'svgr',
7
+ setup(build) {
8
+ build.onLoad({ filter: /\.svg$/ }, async args => {
9
+ // Read file content
10
+ const svg = await fs.promises.readFile(args.path, 'utf8')
11
+
12
+ // Determine relative path
13
+ const relativePath = path.relative(process.cwd(), args.path)
14
+
15
+ // This is an asset ==> dataurl
16
+ if (
17
+ !relativePath.startsWith('src/') ||
18
+ relativePath.startsWith('src/assets/')
19
+ ) {
20
+ return {
21
+ contents: svg,
22
+ loader: 'dataurl',
23
+ }
24
+ }
25
+
26
+ // Otherwise it's a react component
27
+ const contents = await transform(
28
+ svg,
29
+ { ...options },
30
+ { filePath: args.path }
31
+ )
32
+ return {
33
+ contents,
34
+ loader: 'jsx',
35
+ }
36
+ })
37
+ },
38
+ })
39
+
40
+ export default svgPlugin