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

vue

v2.6.21arrow_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
7,755
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
9 months ago
SIZE
N/A
Bit Vuejs Compiler. Compiles and bundles Vue components.
7 contributors
Install vue as a package?
Copied
npm i @bit/bit.envs.bundlers.vue
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Files
index.ts
58 Lines(46 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
import MemoryFS from 'memory-fs';
import path from 'path';
import Vinyl from 'vinyl';
import webpack from 'webpack';
import getConfig from './webpack.config';

const runWebpack = (files: Vinyl[], distPath: string) => {
  return new Promise((resolve, reject) => {
    const fs = new MemoryFS();
    const webPackConfig = getConfig(files, distPath);
    const outputFiles: Vinyl[] = [];

    // 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() && 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: Vinyl[], distPath: string) => {
  if (files.length === 0) {
    return files;
  }
  return runWebpack(files, distPath).then(compiled => {
    return compiled;
  });
};

export default {
  compile
};