Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

vue

v2.5.2arrow_drop_down
v2.6.21
v2.6.20
v2.6.19
v2.6.18
v2.6.17
v2.6.16
v2.6.15
v2.6.13
v2.6.12
v2.6.11
v2.6.10
v2.5.2
v2.5.1
v2.5.0
v0.0.4
v0.0.3
v0.0.2
v0.0.1
STATUS
Passing
DOWNLOADS
6,327
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
10 months ago
SIZE
N/A
Bit Vuejs Compiler. Compiles and bundles Vue components.
7 contributors
Install vue as a package?
Copied
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Files
index.js
61 Lines(49 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import Vinyl from 'vinyl';
import path from 'path';
import webpack from 'webpack';
import MemoryFS from 'memory-fs';
import getConfig from './webpack.config';
 
const runWebpack = (files, distPath, context) => {
  return new Promise ((resolve, reject) => {
    const fs = new MemoryFS();
    const  webPackConfig = getConfig(files, distPath, context);
    const outputFiles = [];
    
    // Init webpack with config
    const compiler = webpack(webPackConfig);

    // Don't write to file system. Write in-memory instead.
    compiler.outputFileSystem = fs;
    
    compiler.run((err, stats) => {
      if (err) {
          reject(err);
      }

      if (stats.hasErrors()) {
          if (stats.errors && stats.errors.length > 0) {
            reject(stats.errors[0]);
          }
          else if (stats.compilation.errors && stats.compilation.errors.length > 0) {
            reject(stats.compilation.errors[0]);
          }
      }

      fs.readdirSync(distPath).forEach(distFileName => { 
        const fileContent = fs.readFileSync(path.join(distPath, distFileName));
        outputFiles.push(new Vinyl({
          contents: fileContent,
          base: distPath,
          path: path.join(distPath, distFileName),
          basename: distFileName,
          // TODO: How to recognize spec files properly?
          test: distFileName.indexOf('.spec.') >=0
        }));
      });

      return resolve(outputFiles)
    });
  });
}

const compile = (files, distPath, context) => {
    if (files.length === 0) {
        return files;
    }
    return runWebpack(files, distPath, context).then(compiled => {
        return compiled;
    });
}

export default {
  compile
};