Skip to content

Commit

Permalink
feat(webpack): add svelte support (#8963)
Browse files Browse the repository at this point in the history
  • Loading branch information
janoshrubos authored and NathanWalker committed Oct 17, 2020
1 parent 3240424 commit 0afea86
Show file tree
Hide file tree
Showing 4 changed files with 387 additions and 7 deletions.
12 changes: 10 additions & 2 deletions packages/webpack/helpers/projectFilesManager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require("path");
const fs = require("fs");

const { isTypeScript, isAngular, isVue, isReact, isShared, isPlugin } = require("./projectHelpers");
const { isTypeScript, isAngular, isVue, isReact, isSvelte, isShared, isPlugin } = require("./projectHelpers");

function addProjectFiles(projectDir) {
const projectTemplates = getProjectTemplates(projectDir);
Expand Down Expand Up @@ -73,6 +73,8 @@ function getProjectTemplates(projectDir) {
templates = getVueTemplates(WEBPACK_CONFIG_NAME);
} else if (isReact({ projectDir })) {
templates = getReactTemplates(WEBPACK_CONFIG_NAME);
} else if (isSvelte({ projectDir })) {
templates = getSvelteTemplates(WEBPACK_CONFIG_NAME);
} else if (isTypeScript({ projectDir })) {
templates = getTypeScriptTemplates(WEBPACK_CONFIG_NAME);
} else {
Expand Down Expand Up @@ -113,6 +115,12 @@ function getReactTemplates(webpackConfigName) {
};
}

function getSvelteTemplates(webpackConfigName) {
return {
"webpack.svelte.js": webpackConfigName
};
}

function getJavaScriptTemplates(webpackConfigName) {
return {
"webpack.javascript.js": webpackConfigName,
Expand Down Expand Up @@ -141,4 +149,4 @@ module.exports = {
removeProjectFiles,
forceUpdateProjectFiles,
compareProjectFiles,
};
};
10 changes: 9 additions & 1 deletion packages/webpack/helpers/projectHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ const isReact = ({ projectDir, packageJson } = {}) => {
.some(dependency => dependency === "react-nativescript");
};

const isSvelte = ({ projectDir, packageJson } = {}) => {
packageJson = packageJson || getPackageJson(projectDir);

return packageJson.dependencies && Object.keys(packageJson.dependencies)
.some(dependency => dependency === "svelte-native");
};

const getPackageJson = projectDir => {
const packageJsonPath = getPackageJsonPath(projectDir);
const result = readJsonFile(packageJsonPath);
Expand Down Expand Up @@ -102,7 +109,7 @@ const getPackageJsonPath = projectDir => {
} else {
return getPackageJsonPath(resolve(projectDir, '..'));
}

}
const getNsConfigPath = projectDir => resolve(projectDir, "nsconfig.json");

Expand Down Expand Up @@ -145,6 +152,7 @@ module.exports = {
getAngularVersion,
isVue,
isReact,
isSvelte,
isTypeScript,
writePackageJson,
convertSlashesInPath,
Expand Down
8 changes: 4 additions & 4 deletions packages/webpack/templates/webpack.config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ const webpackConfigAngular = proxyquire('./webpack.angular', {
fileReplacements: {},
copyReplacements: [],
};
},
hasConfigurations: (envConfigs) => {
return false;
}
},
hasConfigurations: (envConfigs) => {
return false;
},
},
'@nativescript/webpack/utils/ast-utils': {
getMainModulePath: () => {
Expand Down
Loading

0 comments on commit 0afea86

Please sign in to comment.