Skip to content

Commit fda983a

Browse files
committed
Make babel 7 work
1 parent e5a2697 commit fda983a

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

packages/app/src/sandbox/eval/transpiled-module.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,6 @@ export default class TranspiledModule {
766766
localModule.path
767767
);
768768

769-
if (transpiledModule === requiredTranspiledModule) {
770-
throw new Error(`${localModule.path} is importing itself`);
771-
}
772-
773769
// Check if this module has been evaluated before, if so return the exports
774770
// of that compilation
775771
const cache = requiredTranspiledModule.compilation;

packages/app/src/sandbox/eval/transpilers/babel/worker/babel-worker.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from './get-prefixed-name';
1919

2020
let fsInitialized = false;
21+
let lastConfig = null;
2122

2223
async function initializeBrowserFS() {
2324
return new Promise(resolve => {
@@ -242,7 +243,11 @@ self.addEventListener('message', async event => {
242243
);
243244
}
244245

245-
resetCache();
246+
const stringifiedConfig = JSON.stringify(babelTranspilerOptions);
247+
if (lastConfig !== stringifiedConfig) {
248+
resetCache();
249+
lastConfig = stringifiedConfig;
250+
}
246251

247252
const flattenedPresets = flatten(config.presets || []);
248253
const flattenedPlugins = flatten(config.plugins || []);
@@ -340,12 +345,27 @@ self.addEventListener('message', async event => {
340345
}
341346
}
342347

343-
plugins.push(['babel-plugin-detective', { source: true, nodes: true }]);
344-
345-
const customConfig = {
346-
...config,
347-
plugins,
348-
};
348+
plugins.push([
349+
'babel-plugin-detective',
350+
{ source: true, nodes: true, generated: true },
351+
]);
352+
353+
const customConfig = path.startsWith('/node_modules')
354+
? {
355+
plugins: [
356+
version === 7
357+
? 'transform-modules-commonjs'
358+
: 'transform-es2015-modules-commonjs',
359+
[
360+
'babel-plugin-detective',
361+
{ source: true, nodes: true, generated: true },
362+
],
363+
],
364+
}
365+
: {
366+
...config,
367+
plugins,
368+
};
349369

350370
const result = Babel.transform(code, customConfig);
351371

packages/app/src/sandbox/eval/transpilers/babel/worker/evaluate.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ export default function evaluate(
9999
// require.resolve is often used in .babelrc configs to resolve the correct plugin path,
100100
// we want to return a function for that, because our babelrc configs don't really understand
101101
// strings as plugins.
102-
require.resolve = require;
102+
require.resolve = requirePath => requirePath;
103+
// resolve.sync(requirePath, {
104+
// filename: path,
105+
// extensions: ['.js', '.json'],
106+
// moduleDirectory: ['node_modules'],
107+
// });
103108

104109
const module = {
105110
id: path,
@@ -112,7 +117,9 @@ export default function evaluate(
112117
}
113118
finalCode += `\n//# sourceURL=${location.origin}${path}`;
114119

115-
evaluateCode(finalCode, require, module);
120+
evaluateCode(finalCode, require, module, {
121+
VUE_CLI_BABEL_TRANSPILE_MODULES: true,
122+
});
116123

117124
return module.exports;
118125
}

0 commit comments

Comments
 (0)