Skip to content

Commit 6a90da8

Browse files
committed
feat(vera): Add vera type to samples
Modify webpack compilation to accomodate for vue-based widgets.
1 parent 5a9c26d commit 6a90da8

5 files changed

Lines changed: 4012 additions & 175 deletions

File tree

src/cli/compile.js

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const webpack = require('webpack');
33
const path = require('path');
44
const fs = require('fs');
55

6+
const VueLoaderPlugin = require('vue-loader/lib/plugin');
7+
68
const toAbsolutePath = require('./utils').toAbsolutePath;
79
const generateConvertFile = require('./convertFileGenerator');
810

@@ -11,7 +13,6 @@ const fileToDelete = [];
1113
// ----------------------------------------------------------------------------
1214

1315
function buildWebpackConfiguration(name, basepath, outputPath, compress) {
14-
const plugins = [];
1516
const entry = path.join(basepath, 'index.js');
1617
const simputNodeModules = path.join(__dirname, '../../node_modules');
1718
return {
@@ -21,7 +22,9 @@ function buildWebpackConfiguration(name, basepath, outputPath, compress) {
2122
path: outputPath,
2223
filename: `${name}.js`,
2324
},
24-
plugins,
25+
plugins: [
26+
new VueLoaderPlugin(),
27+
],
2528
resolveLoader: {
2629
modules: [simputNodeModules],
2730
},
@@ -33,16 +36,31 @@ function buildWebpackConfiguration(name, basepath, outputPath, compress) {
3336
test: entry,
3437
loader: `expose-loader?Simput.types.${name}`,
3538
},
36-
{ test: /\.(png|jpg)$/, use: 'url-loader?limit=81920' },
37-
{ test: /\.html$/, loader: 'html-loader' },
39+
{ test: /\.(png|jpg|svg)$/, use: 'url-loader?limit=81920' },
3840
{
3941
test: /\.css$/,
42+
exclude: /node_modules/,
43+
use: [
44+
'vue-style-loader',
45+
{
46+
loader: 'css-loader',
47+
options: {
48+
modules: true,
49+
localIdentName: '[folder]-[local]-[sha512:hash:base32:5]',
50+
},
51+
},
52+
],
53+
},
54+
{
55+
test: /\.css$/,
56+
include: /node_modules/,
4057
use: ['style-loader', 'css-loader', 'postcss-loader'],
4158
},
4259
{ test: /\.cjson$/, loader: 'hson-loader' },
4360
{ test: /\.hson$/, loader: 'hson-loader' },
4461
{ test: /\.jade$/i, loader: 'jade-loader' },
4562
{ test: /\.hbs$/i, loader: 'handlebars-loader' },
63+
{ test: /\.vue$/, loader: 'vue-loader' },
4664
{
4765
test: /\.js$/,
4866
use: [
@@ -64,8 +82,31 @@ function buildWebpackConfiguration(name, basepath, outputPath, compress) {
6482
},
6583
],
6684
},
85+
// vtk.js rules
86+
{
87+
test: /\.glsl$/i,
88+
include: /node_modules(\/|\\)vtk\.js(\/|\\)/,
89+
loader: 'shader-loader',
90+
},
91+
{
92+
test: /\.svg$/,
93+
include: /node_modules(\/|\\)vtk\.js(\/|\\)/,
94+
use: [
95+
{ loader: 'raw-loader' },
96+
],
97+
},
6798
],
6899
},
100+
resolve: {
101+
extensions: ['.js', '.vue', '.json'],
102+
alias: {
103+
vue$: 'vue/dist/vue.esm.js',
104+
},
105+
},
106+
externals: {
107+
'vue': 'Vue',
108+
'vuex': 'Vuex',
109+
},
69110
};
70111
}
71112

@@ -170,9 +211,16 @@ module.exports = function compile(
170211
schema = schema.replace('TYPE', modelType);
171212
schema = schema.replace('LANG', lang);
172213

214+
let requireWidgets = '';
215+
216+
if (shell.test('-f', path.join(directory, 'widgets', 'index.js'))) {
217+
requireWidgets = 'require("./widgets/index.js")';
218+
}
219+
173220
fs.writeFileSync(
174221
path.join(directory, 'index.js'),
175-
`module.exports = ${schema}`
222+
`${requireWidgets};
223+
module.exports = ${schema}`
176224
);
177225
fileToDelete.push(path.join(directory, 'index.js'));
178226
webpack(

src/samples/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ export default [
4242
data: {},
4343
},
4444
},
45+
{
46+
label: 'Vera',
47+
icon: 'wb_sunny',
48+
model: {
49+
type: 'vera',
50+
data: {},
51+
},
52+
},
4553
{
4654
label: 'Create your own model type',
4755
icon: 'note_add',

static/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
Simput.registerType('openfoam-periodic', ['./types/openfoam-periodic.js']);
3838

3939
Simput.registerType('oscillator', ['./types/oscillator.js']);
40+
Simput.registerType('vera', ['./types/vera.js']);
4041

4142
// Test / debug --- only for dev
4243
Simput.registerType('addressbook', ['./types/addressbook.js']);

0 commit comments

Comments
 (0)