@imtf/profile-scripts 1.0.3 → 1.0.7

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,48 @@
1
+ # Versions
2
+
3
+ Here you can find a resume of all changes between versions.
4
+
5
+ ## 1.0.7
6
+
7
+ ### Features
8
+
9
+ - Use svgo to dedupe svgs ids and other optimizations
10
+
11
+ ## 1.0.6
12
+
13
+ ### Features
14
+
15
+ - Load css (.css) as text (they are no longer built in a separate .css files)
16
+
17
+ ## 1.0.5
18
+
19
+ ### Bug fixes
20
+
21
+ - Npm package issues fixed.
22
+
23
+ ## 1.0.4
24
+
25
+ ### Features
26
+
27
+ - Use differents loaders for svgs :
28
+ * Svgs part of /src except ones that are in /src/assets will be
29
+ loaded as React components with svgr.
30
+ * Others will be loaded as dataurl (base64)
31
+
32
+ ## 1.0.3
33
+
34
+ ### Features
35
+
36
+ - Load fonts (.ttf, .eot) and images (.gif, .svg) within js file as data-urls
37
+
38
+ ## 1.0.2
39
+
40
+ ### Features
41
+
42
+ - Load fonts (.woff, .woff2) and images (.jpg, .png) within js file as data-urls
43
+
44
+ ## 1.0.1
45
+
46
+ ### Bug fixes
47
+
48
+ - 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.3",
3
+ "version": "1.0.7",
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,16 @@
25
25
  "license": "UNLICENSED",
26
26
  "private": false,
27
27
  "dependencies": {
28
- "concurrently": "^6.2.1",
28
+ "@svgr/core": "^6.2.0",
29
+ "@svgr/plugin-jsx": "^6.2.0",
30
+ "@svgr/plugin-svgo": "^6.2.0",
31
+ "concurrently": "^7.0.0",
29
32
  "esbuild": "^0.14.8",
30
33
  "esbuild-plugin-external-global": "^1.0.1",
31
- "esbuild-plugin-svgr": "^1.0.0",
32
34
  "serve": "^13.0.2"
33
35
  },
34
36
  "devDependencies": {
35
- "@imtf/prettier-config": "^1.0.0",
36
- "@imtf/eslint-config-react": "^1.0.0"
37
+ "@imtf/eslint-config-react": "^1.0.0",
38
+ "@imtf/prettier-config": "^1.0.0"
37
39
  }
38
40
  }
@@ -1,13 +1,15 @@
1
1
  import { build } from 'esbuild'
2
2
  import externalGlobalPlugin from 'esbuild-plugin-external-global'
3
- import svgrPlugin from 'esbuild-plugin-svgr'
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({
9
10
  entryPoints: ['src/index.js'],
10
- outfile: 'build/index.js',
11
+ // outfile: 'build/index.js',
12
+ outdir: 'build',
11
13
  platform: 'browser',
12
14
  bundle: true,
13
15
  target: 'es6',
@@ -25,9 +27,9 @@ build({
25
27
  minify:
26
28
  process.env.NODE_ENV === 'production' &&
27
29
  process.env.IMTF_MINIFY_WEBAPP !== 'false',
28
- // jsx: 'transform',
29
30
  loader: {
30
31
  // Enable JSX in .js files too
32
+ '.css': 'text',
31
33
  '.js': 'jsx',
32
34
  // Embed fonts
33
35
  '.eot': 'dataurl',
@@ -40,7 +42,7 @@ build({
40
42
  '.png': 'dataurl',
41
43
  },
42
44
  plugins: [
43
- svgrPlugin(),
45
+ svgPlugin(),
44
46
  externalGlobalPlugin.externalGlobalPlugin({
45
47
  react: 'window.React',
46
48
  'react-dom': 'window.ReactDOM',
@@ -0,0 +1,44 @@
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
+ {
30
+ plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx'],
31
+ ...options,
32
+ },
33
+ { filePath: args.path }
34
+ )
35
+
36
+ return {
37
+ contents,
38
+ loader: 'jsx',
39
+ }
40
+ })
41
+ },
42
+ })
43
+
44
+ export default svgPlugin