From 28cc6cebe7f9e1d6341d6efcbb00984046372046 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Tue, 9 May 2017 17:41:28 +0300 Subject: [PATCH 1/5] refactor: move templates to separate dir --- .../tsconfig.aot.json.template | 0 .../vendor-platform.android.ts.template | 0 .../vendor-platform.ios.ts.template | 0 .../vendor.ts.angular.template | 0 .../vendor.ts.nativescript.template | 0 .../webpack.android.js.template | 0 .../webpack.common.js.angular.template | 0 .../webpack.common.js.javascript.template | 0 .../webpack.common.js.typescript.template | 0 webpack.ios.js.template => templates/webpack.ios.js.template | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename tsconfig.aot.json.template => templates/tsconfig.aot.json.template (100%) rename vendor-platform.android.ts.template => templates/vendor-platform.android.ts.template (100%) rename vendor-platform.ios.ts.template => templates/vendor-platform.ios.ts.template (100%) rename vendor.ts.angular.template => templates/vendor.ts.angular.template (100%) rename vendor.ts.nativescript.template => templates/vendor.ts.nativescript.template (100%) rename webpack.android.js.template => templates/webpack.android.js.template (100%) rename webpack.common.js.angular.template => templates/webpack.common.js.angular.template (100%) rename webpack.common.js.javascript.template => templates/webpack.common.js.javascript.template (100%) rename webpack.common.js.typescript.template => templates/webpack.common.js.typescript.template (100%) rename webpack.ios.js.template => templates/webpack.ios.js.template (100%) diff --git a/tsconfig.aot.json.template b/templates/tsconfig.aot.json.template similarity index 100% rename from tsconfig.aot.json.template rename to templates/tsconfig.aot.json.template diff --git a/vendor-platform.android.ts.template b/templates/vendor-platform.android.ts.template similarity index 100% rename from vendor-platform.android.ts.template rename to templates/vendor-platform.android.ts.template diff --git a/vendor-platform.ios.ts.template b/templates/vendor-platform.ios.ts.template similarity index 100% rename from vendor-platform.ios.ts.template rename to templates/vendor-platform.ios.ts.template diff --git a/vendor.ts.angular.template b/templates/vendor.ts.angular.template similarity index 100% rename from vendor.ts.angular.template rename to templates/vendor.ts.angular.template diff --git a/vendor.ts.nativescript.template b/templates/vendor.ts.nativescript.template similarity index 100% rename from vendor.ts.nativescript.template rename to templates/vendor.ts.nativescript.template diff --git a/webpack.android.js.template b/templates/webpack.android.js.template similarity index 100% rename from webpack.android.js.template rename to templates/webpack.android.js.template diff --git a/webpack.common.js.angular.template b/templates/webpack.common.js.angular.template similarity index 100% rename from webpack.common.js.angular.template rename to templates/webpack.common.js.angular.template diff --git a/webpack.common.js.javascript.template b/templates/webpack.common.js.javascript.template similarity index 100% rename from webpack.common.js.javascript.template rename to templates/webpack.common.js.javascript.template diff --git a/webpack.common.js.typescript.template b/templates/webpack.common.js.typescript.template similarity index 100% rename from webpack.common.js.typescript.template rename to templates/webpack.common.js.typescript.template diff --git a/webpack.ios.js.template b/templates/webpack.ios.js.template similarity index 100% rename from webpack.ios.js.template rename to templates/webpack.ios.js.template From e4a556c56a0954a792d1042a5d6dbf5e24d0b266 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Wed, 10 May 2017 11:53:12 +0300 Subject: [PATCH 2/5] refactor: generate webpack.common templates on prepublish --- package.json | 3 +- projectFilesManager.js | 16 +- templates/buildTemplates.js | 66 ++++++ templates/common/exports.js | 56 +++++ templates/common/getPlatform.js | 8 + templates/common/imports.js | 9 + templates/common/plugins.js | 28 +++ templates/common/rules.js | 37 ++++ templates/common/uglify.js | 11 + templates/js/getExtensions.js | 11 + templates/ng/getExtensions.js | 14 ++ templates/ng/imports.js | 1 + templates/ng/plugins.js | 11 + templates/ng/rules.js | 10 + templates/ts/getExtensions.js | 13 ++ templates/ts/rules.js | 9 + templates/webpack.android.js.template | 2 - templates/webpack.common.js.angular.template | 151 -------------- .../webpack.common.js.javascript.template | 128 ------------ templates/webpack.common.js.js.template | 166 +++++++++++++++ templates/webpack.common.js.ng.template | 191 ++++++++++++++++++ templates/webpack.common.js.ts.template | 169 ++++++++++++++++ .../webpack.common.js.typescript.template | 137 ------------- templates/webpack.ios.js.template | 2 - 24 files changed, 819 insertions(+), 430 deletions(-) create mode 100644 templates/buildTemplates.js create mode 100644 templates/common/exports.js create mode 100644 templates/common/getPlatform.js create mode 100644 templates/common/imports.js create mode 100644 templates/common/plugins.js create mode 100644 templates/common/rules.js create mode 100644 templates/common/uglify.js create mode 100644 templates/js/getExtensions.js create mode 100644 templates/ng/getExtensions.js create mode 100644 templates/ng/imports.js create mode 100644 templates/ng/plugins.js create mode 100644 templates/ng/rules.js create mode 100644 templates/ts/getExtensions.js create mode 100644 templates/ts/rules.js delete mode 100644 templates/webpack.android.js.template delete mode 100644 templates/webpack.common.js.angular.template delete mode 100644 templates/webpack.common.js.javascript.template create mode 100644 templates/webpack.common.js.js.template create mode 100644 templates/webpack.common.js.ng.template create mode 100644 templates/webpack.common.js.ts.template delete mode 100644 templates/webpack.common.js.typescript.template delete mode 100644 templates/webpack.ios.js.template diff --git a/package.json b/package.json index 7c8d5bfd..274705de 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "url": "https://github.com/NativeScript/nativescript-dev-webpack.git" }, "scripts": { - "postinstall": "node postinstall.js" + "postinstall": "node postinstall.js", + "prepublishOnly": "node ./templates/buildTemplates.js" }, "bin": { "install-ns-webpack": "./bin/install-ns-webpack", diff --git a/projectFilesManager.js b/projectFilesManager.js index e4e58ba3..4b6a093a 100644 --- a/projectFilesManager.js +++ b/projectFilesManager.js @@ -7,7 +7,7 @@ function addProjectFiles(projectDir, appDir) { const projectTemplates = getProjectTemplates(projectDir); Object.keys(projectTemplates).forEach(function(templateName) { const templateDestination = projectTemplates[templateName]; - templateName = path.resolve(templateName) + templateName = path.resolve(templateName); copyTemplate(templateName, templateDestination); }); @@ -43,24 +43,22 @@ function copyTemplate(templateName, destinationPath) { // Create destination file, only if not present. if (!fs.existsSync(destinationPath)) { console.info(`Creating file: ${destinationPath}`); + console.log(templateName) const content = fs.readFileSync(templateName, "utf8"); fs.writeFileSync(destinationPath, content); } } function getProjectTemplates(projectDir) { - let templates = { - "webpack.android.js.template": "webpack.android.js", - "webpack.ios.js.template": "webpack.ios.js", - }; + let templates = {} if (helpers.isAngular({projectDir})) { - templates["webpack.common.js.angular.template"] = "webpack.common.js"; + templates["webpack.common.js.ng.template"] = "webpack.common.js"; templates["tsconfig.aot.json.template"] = "tsconfig.aot.json"; } else if (helpers.isTypeScript({projectDir})) { - templates["webpack.common.js.typescript.template"] = "webpack.common.js"; + templates["webpack.common.js.ts.template"] = "webpack.common.js"; } else { - templates["webpack.common.js.javascript.template"] = "webpack.common.js"; + templates["webpack.common.js.js.template"] = "webpack.common.js"; } return getFullTemplatesPath(projectDir, templates); @@ -85,7 +83,7 @@ function getFullTemplatesPath(projectDir, templates) { let updatedTemplates = {}; Object.keys(templates).forEach(key => { - const updatedKey = getFullPath(__dirname, key); + const updatedKey = getFullPath(path.join(__dirname, "templates"), key); const updatedValue = getFullPath(projectDir, templates[key]) updatedTemplates[updatedKey] = updatedValue; diff --git a/templates/buildTemplates.js b/templates/buildTemplates.js new file mode 100644 index 00000000..0ed0829a --- /dev/null +++ b/templates/buildTemplates.js @@ -0,0 +1,66 @@ +const { writeFileSync } = require("fs"); + +saveTemplate("js"); +saveTemplate("ts"); +saveTemplate("ng"); + +function saveTemplate(target) { + const content = buildTemplate(target); + writeFileSync(`./templates/webpack.common.js.${target}.template`, content); +} + +function buildTemplate(target) { + let template = ""; + + template += getResource(target, "imports"); + template += getResource(target, "exports"); + template += getResource(target, "getPlatform"); + + const rules = getResource(target, "rules"); + template += rulesBuilder(rules); + + const plugins = getResource(target, "plugins"); + template += pluginsBuilder(plugins); + + template += require(`./${target}/getExtensions`); + + return template; +}; + +function getResource(target, resourceName) { + const common = require(`./common/${resourceName}`); + const maybeSpecific = tryRequire(`./${target}/${resourceName}`); + + return merge(resourceName, common, maybeSpecific); +} + +function tryRequire(path) { + try { + return require(path); + } catch(e) { } +} + +function merge(resource, common, specific) { + const allResources = specific ? `${common}\n${specific}\n` : `${common}\n`; + return isArray(resource) ? `[${allResources} ]` : allResources; +} + +function isArray(resource) { + return ["rules", "plugins"].includes(resource); +} + +function pluginsBuilder(plugins) { + const uglify = require("./common/uglify"); + return `function getPlugins(platform, env) { + let plugins = ${plugins}; + ${uglify} + + return plugins; +}\n`; +} + +function rulesBuilder(rules) { + return `function getRules() { + return ${rules}; +}\n\n`; +} diff --git a/templates/common/exports.js b/templates/common/exports.js new file mode 100644 index 00000000..0ba564b0 --- /dev/null +++ b/templates/common/exports.js @@ -0,0 +1,56 @@ +module.exports = ` +const mainSheet = \`app.css\`; + +module.exports = env => { + const platform = getPlatform(env); + + // Default destination inside platforms//... + const path = resolve(nsWebpack.getAppPath(platform)); + + const entry = { + // Discover entry module from package.json + bundle: \`./\${nsWebpack.getEntryModule()}\`, + + // Vendor entry with third-party libraries + vendor: \`./vendor\`, + + // Entry for stylesheet with global application styles + [mainSheet]: \`./\${mainSheet}\`, + }; + + const rules = getRules(); + const plugins = getPlugins(platform, env); + const extensions = getExtensions(platform); + + return { + context: resolve("./app"), + target: nativescriptTarget, + entry, + output: { + pathinfo: true, + path, + libraryTarget: "commonjs2", + filename: "[name].js", + }, + resolve: { + extensions, + + // Resolve {N} system modules from tns-core-modules + modules: [ + "node_modules/tns-core-modules", + "node_modules", + ] + }, + node: { + // Disable node shims that conflict with NativeScript + "http": false, + "timers": false, + "setImmediate": false, + "fs": "empty", + }, + module: { rules }, + plugins, + }; +}; +`; + diff --git a/templates/common/getPlatform.js b/templates/common/getPlatform.js new file mode 100644 index 00000000..6cd90a4f --- /dev/null +++ b/templates/common/getPlatform.js @@ -0,0 +1,8 @@ +module.exports = ` +function getPlatform(env) { + return env.android ? "android" : + env.ios ? "ios" : + () => { throw new Error("You need to provide a target platform!") }; +} +`; + diff --git a/templates/common/imports.js b/templates/common/imports.js new file mode 100644 index 00000000..fdc54d90 --- /dev/null +++ b/templates/common/imports.js @@ -0,0 +1,9 @@ +module.exports = ` +const { resolve, join } = require("path"); + +const webpack = require("webpack"); +const nsWebpack = require("nativescript-dev-webpack"); +const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); +const ExtractTextPlugin = require("extract-text-webpack-plugin"); +`; diff --git a/templates/common/plugins.js b/templates/common/plugins.js new file mode 100644 index 00000000..c975a824 --- /dev/null +++ b/templates/common/plugins.js @@ -0,0 +1,28 @@ +module.exports = ` + new ExtractTextPlugin(mainSheet), + + // Vendor libs go to the vendor.js chunk + new webpack.optimize.CommonsChunkPlugin({ + name: ["vendor"], + }), + + // Define useful constants like TNS_WEBPACK + new webpack.DefinePlugin({ + "global.TNS_WEBPACK": "true", + }), + + // Copy assets to out dir. Add your own globs as needed. + new CopyWebpackPlugin([ + { from: mainSheet }, + { from: "css/**" }, + { from: "fonts/**" }, + { from: "**/*.jpg" }, + { from: "**/*.png" }, + { from: "**/*.xml" }, + ], { ignore: ["App_Resources/**"] }), + + // Generate a bundle starter script and activate it in package.json + new nsWebpack.GenerateBundleStarterPlugin([ + "./vendor", + "./bundle", + ]),`; diff --git a/templates/common/rules.js b/templates/common/rules.js new file mode 100644 index 00000000..3c43b69a --- /dev/null +++ b/templates/common/rules.js @@ -0,0 +1,37 @@ +module.exports = ` + { + test: /\\.html$|\\.xml$/, + use: [ + "raw-loader", + ] + }, + // Root stylesheet gets extracted with bundled dependencies + { + test: new RegExp(mainSheet), + use: ExtractTextPlugin.extract([ + { + loader: "resolve-url-loader", + options: { silent: true }, + }, + "nativescript-css-loader", + "nativescript-dev-webpack/platform-css-loader", + ]), + }, + // Other CSS files get bundled using the raw loader + { + test: /\\.css$/, + exclude: new RegExp(mainSheet), + use: [ + "raw-loader", + ] + }, + // SASS support + { + test: /\\.scss$/, + use: [ + "raw-loader", + "resolve-url-loader", + "sass-loader", + ] + }, +`; diff --git a/templates/common/uglify.js b/templates/common/uglify.js new file mode 100644 index 00000000..ef57ad82 --- /dev/null +++ b/templates/common/uglify.js @@ -0,0 +1,11 @@ +module.exports = ` + if (env.uglify) { + plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true })); + + // Work around an Android issue by setting compress = false + const compress = platform !== "android"; + plugins.push(new webpack.optimize.UglifyJsPlugin({ + mangle: { except: nsWebpack.uglifyMangleExcludes }, + compress, + })); + }`; diff --git a/templates/js/getExtensions.js b/templates/js/getExtensions.js new file mode 100644 index 00000000..e49eb5b2 --- /dev/null +++ b/templates/js/getExtensions.js @@ -0,0 +1,11 @@ +module.exports = ` +// Resolve platform-specific modules like module.android.js +function getExtensions(platform) { + return Object.freeze([ + \`.\${platform}.js\`, + \`.\${platform}.css\`, + ".js", + ".css", + ]); +} +`; diff --git a/templates/ng/getExtensions.js b/templates/ng/getExtensions.js new file mode 100644 index 00000000..6f5ff8b5 --- /dev/null +++ b/templates/ng/getExtensions.js @@ -0,0 +1,14 @@ +module.exports = ` +// Resolve platform-specific modules like module.android.js +function getExtensions(platform) { + return Object.freeze([ + \`.\${platform}.ts\`, + \`.\${platform}.js\`, + \`.\${platform}.css\`, + ".aot.ts", + ".ts", + ".js", + ".css", + ]); +} +`; diff --git a/templates/ng/imports.js b/templates/ng/imports.js new file mode 100644 index 00000000..5dd1e1f4 --- /dev/null +++ b/templates/ng/imports.js @@ -0,0 +1 @@ +module.exports = `const { AotPlugin } = require("@ngtools/webpack");`; diff --git a/templates/ng/plugins.js b/templates/ng/plugins.js new file mode 100644 index 00000000..a09d8105 --- /dev/null +++ b/templates/ng/plugins.js @@ -0,0 +1,11 @@ +module.exports = ` + // Angular AOT compiler + new AotPlugin({ + tsConfigPath: "tsconfig.aot.json", + entryModule: resolve(__dirname, "app/app.module#AppModule"), + typeChecking: false + }), + + // Resolve .ios.css and .android.css component stylesheets + new nsWebpack.StyleUrlResolvePlugin({platform}), +`; diff --git a/templates/ng/rules.js b/templates/ng/rules.js new file mode 100644 index 00000000..42415e3d --- /dev/null +++ b/templates/ng/rules.js @@ -0,0 +1,10 @@ +module.exports = ` + // Compile TypeScript files with ahead-of-time compiler. + { + test: /\\.ts$/, + loaders: [ + "nativescript-dev-webpack/tns-aot-loader", + "@ngtools/webpack", + ] + } +`; diff --git a/templates/ts/getExtensions.js b/templates/ts/getExtensions.js new file mode 100644 index 00000000..cf35cc24 --- /dev/null +++ b/templates/ts/getExtensions.js @@ -0,0 +1,13 @@ +module.exports = ` +// Resolve platform-specific modules like module.android.js +function getExtensions(platform) { + return Object.freeze([ + \`.\${platform}.ts\`, + \`.\${platform}.js\`, + \`.\${platform}.css\`, + ".ts", + ".js", + ".css", + ]); +} +`; diff --git a/templates/ts/rules.js b/templates/ts/rules.js new file mode 100644 index 00000000..5ea507c9 --- /dev/null +++ b/templates/ts/rules.js @@ -0,0 +1,9 @@ +module.exports = [ + // Compile TypeScript files, replace templateUrl and styleUrls. + { + test: /\\.ts$/, + loaders: [ + "awesome-typescript-loader", + ] + } +]; diff --git a/templates/webpack.android.js.template b/templates/webpack.android.js.template deleted file mode 100644 index 968e93b8..00000000 --- a/templates/webpack.android.js.template +++ /dev/null @@ -1,2 +0,0 @@ -var makeConfig = require("./webpack.common"); -module.exports = makeConfig("android"); diff --git a/templates/webpack.common.js.angular.template b/templates/webpack.common.js.angular.template deleted file mode 100644 index 57f2916d..00000000 --- a/templates/webpack.common.js.angular.template +++ /dev/null @@ -1,151 +0,0 @@ -var webpack = require("webpack"); -var nsWebpack = require("nativescript-dev-webpack"); -var nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); -var path = require("path"); -var CopyWebpackPlugin = require("copy-webpack-plugin"); -var ExtractTextPlugin = require("extract-text-webpack-plugin"); -var AotPlugin = require("@ngtools/webpack").AotPlugin; - -module.exports = function (platform, destinationApp) { - if (!destinationApp) { - //Default destination inside platforms//... - destinationApp = nsWebpack.getAppPath(platform); - } - var entry = {}; - // Discover entry module from package.json - entry.bundle = "./" + nsWebpack.getEntryModule(); - //Vendor entry with third party libraries. - entry.vendor = "./vendor"; - // app.css bundle - entry["app.css"] = "./app.css"; - - var plugins = [ - new ExtractTextPlugin("app.css"), - new webpack.optimize.CommonsChunkPlugin({ - // Vendor libs go to the vendor.js chunk - name: ["vendor"] - }), - // Define useful constants like TNS_WEBPACK - new webpack.DefinePlugin({ - "global.TNS_WEBPACK": "true", - }), - // Copy assets to out dir. Add your own globs as needed. - new CopyWebpackPlugin([ - { from: "app.css" }, - { from: "css/**" }, - { from: "fonts/**" }, - { from: "**/*.jpg" }, - { from: "**/*.png" }, - { from: "**/*.xml" }, - ], { ignore: ["App_Resources/**"] }), - // Generate a bundle starter script and activate it in package.json - new nsWebpack.GenerateBundleStarterPlugin([ - "./vendor", - "./bundle", - ]), - - // Angular AOT compiler - new AotPlugin({ - tsConfigPath: "tsconfig.aot.json", - entryModule: path.resolve(__dirname, "app/app.module#AppModule"), - typeChecking: false - }), - new nsWebpack.StyleUrlResolvePlugin({platform}), - ]; - - if (process.env.npm_config_uglify) { - plugins.push(new webpack.LoaderOptionsPlugin({ - minimize: true - })); - - // Work around an Android issue by setting compress = false - var compress = platform !== "android"; - plugins.push(new webpack.optimize.UglifyJsPlugin({ - mangle: { - except: nsWebpack.uglifyMangleExcludes, - }, - compress: compress, - })); - } - - return { - context: path.resolve("./app"), - target: nativescriptTarget, - entry: entry, - output: { - pathinfo: true, - path: path.resolve(destinationApp), - libraryTarget: "commonjs2", - filename: "[name].js", - }, - resolve: { - // Resolve platform-specific modules like module.android.js - extensions: [ - "." + platform + ".ts", - "." + platform + ".js", - "." + platform + ".css", - ".aot.ts", - ".ts", - ".js", - ".css", - ], - // Resolve {N} system modules from tns-core-modules - modules: [ - "node_modules/tns-core-modules", - "node_modules", - ] - }, - node: { - // Disable node shims that conflict with NativeScript - "http": false, - "timers": false, - "setImmediate": false, - "fs": "empty", - }, - module: { - loaders: [ - { - test: /\.html$|\.xml$/, - loaders: [ - "raw-loader", - ] - }, - // Root app.css file gets extracted with bundled dependencies - { - test: /app\.css$/, - loader: ExtractTextPlugin.extract([ - "resolve-url-loader", - "nativescript-css-loader", - "nativescript-dev-webpack/platform-css-loader", - ]), - }, - // Other CSS files get bundled using the raw loader - { - test: /\.css$/, - exclude: /app\.css$/, - loaders: [ - "raw-loader", - ] - }, - // Compile TypeScript files with ahead-of-time compiler. - { - test: /\.ts$/, - loaders: [ - "nativescript-dev-webpack/tns-aot-loader", - "@ngtools/webpack", - ] - }, - // SASS support - { - test: /\.scss$/, - loaders: [ - "raw-loader", - "resolve-url-loader", - "sass-loader", - ] - }, - ] - }, - plugins: plugins, - }; -}; diff --git a/templates/webpack.common.js.javascript.template b/templates/webpack.common.js.javascript.template deleted file mode 100644 index 6b397063..00000000 --- a/templates/webpack.common.js.javascript.template +++ /dev/null @@ -1,128 +0,0 @@ -var webpack = require("webpack"); -var nsWebpack = require("nativescript-dev-webpack"); -var nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); -var path = require("path"); -var CopyWebpackPlugin = require("copy-webpack-plugin"); -var ExtractTextPlugin = require("extract-text-webpack-plugin"); - -module.exports = function (platform, destinationApp) { - if (!destinationApp) { - // Default destination inside platforms//... - destinationApp = nsWebpack.getAppPath(platform); - } - var entry = {}; - // Discover entry module from package.json - entry.bundle = "./" + nsWebpack.getEntryModule(); - // Vendor entry with third party libraries. - entry.vendor = "./vendor"; - // app.css bundle - entry["app.css"] = "./app.css"; - - var plugins = [ - new ExtractTextPlugin("app.css"), - new webpack.optimize.CommonsChunkPlugin({ - name: ["vendor"] - }), - // Define useful constants like TNS_WEBPACK - new webpack.DefinePlugin({ - "global.TNS_WEBPACK": "true", - }), - // Copy assets to out dir. Add your own globs as needed. - new CopyWebpackPlugin([ - { from: "app.css" }, - { from: "css/**" }, - { from: "fonts/**" }, - { from: "**/*.jpg" }, - { from: "**/*.png" }, - { from: "**/*.xml" }, - ], { ignore: ["App_Resources/**"] }), - // Generate a bundle starter script and activate it in package.json - new nsWebpack.GenerateBundleStarterPlugin([ - "./vendor", - "./bundle", - ]), - ]; - - if (process.env.npm_config_uglify) { - plugins.push(new webpack.LoaderOptionsPlugin({ - minimize: true - })); - - // Work around an Android issue by setting compress = false - var compress = platform !== "android"; - plugins.push(new webpack.optimize.UglifyJsPlugin({ - mangle: { - except: nsWebpack.uglifyMangleExcludes, - }, - compress: compress, - })); - } - - return { - context: path.resolve("./app"), - target: nativescriptTarget, - entry: entry, - output: { - pathinfo: true, - path: path.resolve(destinationApp), - libraryTarget: "commonjs2", - filename: "[name].js", - }, - resolve: { - // Resolve platform-specific modules like module.android.js - extensions: [ - "." + platform + ".js", - "." + platform + ".css", - ".js", - ".css", - ], - // Resolve {N} system modules from tns-core-modules - modules: [ - "node_modules/tns-core-modules", - "node_modules", - ] - }, - node: { - // Disable node shims that conflict with NativeScript - "http": false, - "timers": false, - "setImmediate": false, - "fs": "empty", - }, - module: { - loaders: [ - { - test: /\.html$/, - loader: "raw-loader" - }, - // Root app.css file gets extracted with bundled dependencies - { - test: /app\.css$/, - loader: ExtractTextPlugin.extract([ - "resolve-url-loader", - "nativescript-css-loader", - "nativescript-dev-webpack/platform-css-loader", - ]), - }, - // Other CSS files get bundled using the raw loader - { - test: /\.css$/, - exclude: /app\.css$/, - loaders: [ - "raw-loader", - ] - }, - // SASS support - { - test: /\.scss$/, - loaders: [ - "raw-loader", - "resolve-url-loader", - "sass-loader", - ] - }, - ] - }, - plugins: plugins, - }; -}; diff --git a/templates/webpack.common.js.js.template b/templates/webpack.common.js.js.template new file mode 100644 index 00000000..bb35c0fe --- /dev/null +++ b/templates/webpack.common.js.js.template @@ -0,0 +1,166 @@ + +const { resolve, join } = require("path"); + +const webpack = require("webpack"); +const nsWebpack = require("nativescript-dev-webpack"); +const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); +const ExtractTextPlugin = require("extract-text-webpack-plugin"); + + +const mainSheet = `app.css`; + +module.exports = env => { + const platform = getPlatform(env); + + // Default destination inside platforms//... + const path = resolve(nsWebpack.getAppPath(platform)); + + const entry = { + // Discover entry module from package.json + bundle: `./${nsWebpack.getEntryModule()}`, + + // Vendor entry with third-party libraries + vendor: `./vendor`, + + // Entry for stylesheet with global application styles + [mainSheet]: `./${mainSheet}`, + }; + + const rules = getRules(); + const plugins = getPlugins(platform, env); + const extensions = getExtensions(platform); + + return { + context: resolve("./app"), + target: nativescriptTarget, + entry, + output: { + pathinfo: true, + path, + libraryTarget: "commonjs2", + filename: "[name].js", + }, + resolve: { + extensions, + + // Resolve {N} system modules from tns-core-modules + modules: [ + "node_modules/tns-core-modules", + "node_modules", + ] + }, + node: { + // Disable node shims that conflict with NativeScript + "http": false, + "timers": false, + "setImmediate": false, + "fs": "empty", + }, + module: { rules }, + plugins, + }; +}; + + +function getPlatform(env) { + return env.android ? "android" : + env.ios ? "ios" : + () => { throw new Error("You need to provide a target platform!") }; +} + +function getRules() { + return [ + { + test: /\.html$|\.xml$/, + use: [ + "raw-loader", + ] + }, + // Root stylesheet gets extracted with bundled dependencies + { + test: new RegExp(mainSheet), + use: ExtractTextPlugin.extract([ + { + loader: "resolve-url-loader", + options: { silent: true }, + }, + "nativescript-css-loader", + "nativescript-dev-webpack/platform-css-loader", + ]), + }, + // Other CSS files get bundled using the raw loader + { + test: /\.css$/, + exclude: new RegExp(mainSheet), + use: [ + "raw-loader", + ] + }, + // SASS support + { + test: /\.scss$/, + use: [ + "raw-loader", + "resolve-url-loader", + "sass-loader", + ] + }, + + ]; +} + +function getPlugins(platform, env) { + let plugins = [ + new ExtractTextPlugin(mainSheet), + + // Vendor libs go to the vendor.js chunk + new webpack.optimize.CommonsChunkPlugin({ + name: ["vendor"], + }), + + // Define useful constants like TNS_WEBPACK + new webpack.DefinePlugin({ + "global.TNS_WEBPACK": "true", + }), + + // Copy assets to out dir. Add your own globs as needed. + new CopyWebpackPlugin([ + { from: mainSheet }, + { from: "css/**" }, + { from: "fonts/**" }, + { from: "**/*.jpg" }, + { from: "**/*.png" }, + { from: "**/*.xml" }, + ], { ignore: ["App_Resources/**"] }), + + // Generate a bundle starter script and activate it in package.json + new nsWebpack.GenerateBundleStarterPlugin([ + "./vendor", + "./bundle", + ]), + ]; + + if (env.uglify) { + plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true })); + + // Work around an Android issue by setting compress = false + const compress = platform !== "android"; + plugins.push(new webpack.optimize.UglifyJsPlugin({ + mangle: { except: nsWebpack.uglifyMangleExcludes }, + compress, + })); + } + + return plugins; +} + +// Resolve platform-specific modules like module.android.js +function getExtensions(platform) { + return Object.freeze([ + `.${platform}.js`, + `.${platform}.css`, + ".js", + ".css", + ]); +} diff --git a/templates/webpack.common.js.ng.template b/templates/webpack.common.js.ng.template new file mode 100644 index 00000000..af57d05b --- /dev/null +++ b/templates/webpack.common.js.ng.template @@ -0,0 +1,191 @@ + +const { resolve, join } = require("path"); + +const webpack = require("webpack"); +const nsWebpack = require("nativescript-dev-webpack"); +const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); +const ExtractTextPlugin = require("extract-text-webpack-plugin"); + +const { AotPlugin } = require("@ngtools/webpack"); + +const mainSheet = `app.css`; + +module.exports = env => { + const platform = getPlatform(env); + + // Default destination inside platforms//... + const path = resolve(nsWebpack.getAppPath(platform)); + + const entry = { + // Discover entry module from package.json + bundle: `./${nsWebpack.getEntryModule()}`, + + // Vendor entry with third-party libraries + vendor: `./vendor`, + + // Entry for stylesheet with global application styles + [mainSheet]: `./${mainSheet}`, + }; + + const rules = getRules(); + const plugins = getPlugins(platform, env); + const extensions = getExtensions(platform); + + return { + context: resolve("./app"), + target: nativescriptTarget, + entry, + output: { + pathinfo: true, + path, + libraryTarget: "commonjs2", + filename: "[name].js", + }, + resolve: { + extensions, + + // Resolve {N} system modules from tns-core-modules + modules: [ + "node_modules/tns-core-modules", + "node_modules", + ] + }, + node: { + // Disable node shims that conflict with NativeScript + "http": false, + "timers": false, + "setImmediate": false, + "fs": "empty", + }, + module: { rules }, + plugins, + }; +}; + + +function getPlatform(env) { + return env.android ? "android" : + env.ios ? "ios" : + () => { throw new Error("You need to provide a target platform!") }; +} + +function getRules() { + return [ + { + test: /\.html$|\.xml$/, + use: [ + "raw-loader", + ] + }, + // Root stylesheet gets extracted with bundled dependencies + { + test: new RegExp(mainSheet), + use: ExtractTextPlugin.extract([ + { + loader: "resolve-url-loader", + options: { silent: true }, + }, + "nativescript-css-loader", + "nativescript-dev-webpack/platform-css-loader", + ]), + }, + // Other CSS files get bundled using the raw loader + { + test: /\.css$/, + exclude: new RegExp(mainSheet), + use: [ + "raw-loader", + ] + }, + // SASS support + { + test: /\.scss$/, + use: [ + "raw-loader", + "resolve-url-loader", + "sass-loader", + ] + }, + + + // Compile TypeScript files with ahead-of-time compiler. + { + test: /\.ts$/, + loaders: [ + "nativescript-dev-webpack/tns-aot-loader", + "@ngtools/webpack", + ] + } + + ]; +} + +function getPlugins(platform, env) { + let plugins = [ + new ExtractTextPlugin(mainSheet), + + // Vendor libs go to the vendor.js chunk + new webpack.optimize.CommonsChunkPlugin({ + name: ["vendor"], + }), + + // Define useful constants like TNS_WEBPACK + new webpack.DefinePlugin({ + "global.TNS_WEBPACK": "true", + }), + + // Copy assets to out dir. Add your own globs as needed. + new CopyWebpackPlugin([ + { from: mainSheet }, + { from: "css/**" }, + { from: "fonts/**" }, + { from: "**/*.jpg" }, + { from: "**/*.png" }, + { from: "**/*.xml" }, + ], { ignore: ["App_Resources/**"] }), + + // Generate a bundle starter script and activate it in package.json + new nsWebpack.GenerateBundleStarterPlugin([ + "./vendor", + "./bundle", + ]), + + // Angular AOT compiler + new AotPlugin({ + tsConfigPath: "tsconfig.aot.json", + entryModule: resolve(__dirname, "app/app.module#AppModule"), + typeChecking: false + }), + + // Resolve .ios.css and .android.css component stylesheets + new nsWebpack.StyleUrlResolvePlugin({platform}), + + ]; + + if (env.uglify) { + plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true })); + + // Work around an Android issue by setting compress = false + const compress = platform !== "android"; + plugins.push(new webpack.optimize.UglifyJsPlugin({ + mangle: { except: nsWebpack.uglifyMangleExcludes }, + compress, + })); + } + + return plugins; +} + +// Resolve platform-specific modules like module.android.js +function getExtensions(platform) { + return Object.freeze([ + `.${platform}.ts`, + `.${platform}.js`, + `.${platform}.css`, + ".aot.ts", + ".ts", + ".js", + ".css", + ]); +} diff --git a/templates/webpack.common.js.ts.template b/templates/webpack.common.js.ts.template new file mode 100644 index 00000000..6d0ae6e2 --- /dev/null +++ b/templates/webpack.common.js.ts.template @@ -0,0 +1,169 @@ + +const { resolve, join } = require("path"); + +const webpack = require("webpack"); +const nsWebpack = require("nativescript-dev-webpack"); +const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); +const ExtractTextPlugin = require("extract-text-webpack-plugin"); + + +const mainSheet = `app.css`; + +module.exports = env => { + const platform = getPlatform(env); + + // Default destination inside platforms//... + const path = resolve(nsWebpack.getAppPath(platform)); + + const entry = { + // Discover entry module from package.json + bundle: `./${nsWebpack.getEntryModule()}`, + + // Vendor entry with third-party libraries + vendor: `./vendor`, + + // Entry for stylesheet with global application styles + [mainSheet]: `./${mainSheet}`, + }; + + const rules = getRules(); + const plugins = getPlugins(platform, env); + const extensions = getExtensions(platform); + + return { + context: resolve("./app"), + target: nativescriptTarget, + entry, + output: { + pathinfo: true, + path, + libraryTarget: "commonjs2", + filename: "[name].js", + }, + resolve: { + extensions, + + // Resolve {N} system modules from tns-core-modules + modules: [ + "node_modules/tns-core-modules", + "node_modules", + ] + }, + node: { + // Disable node shims that conflict with NativeScript + "http": false, + "timers": false, + "setImmediate": false, + "fs": "empty", + }, + module: { rules }, + plugins, + }; +}; + + +function getPlatform(env) { + return env.android ? "android" : + env.ios ? "ios" : + () => { throw new Error("You need to provide a target platform!") }; +} + +function getRules() { + return [ + { + test: /\.html$|\.xml$/, + use: [ + "raw-loader", + ] + }, + // Root stylesheet gets extracted with bundled dependencies + { + test: new RegExp(mainSheet), + use: ExtractTextPlugin.extract([ + { + loader: "resolve-url-loader", + options: { silent: true }, + }, + "nativescript-css-loader", + "nativescript-dev-webpack/platform-css-loader", + ]), + }, + // Other CSS files get bundled using the raw loader + { + test: /\.css$/, + exclude: new RegExp(mainSheet), + use: [ + "raw-loader", + ] + }, + // SASS support + { + test: /\.scss$/, + use: [ + "raw-loader", + "resolve-url-loader", + "sass-loader", + ] + }, + +[object Object] + ]; +} + +function getPlugins(platform, env) { + let plugins = [ + new ExtractTextPlugin(mainSheet), + + // Vendor libs go to the vendor.js chunk + new webpack.optimize.CommonsChunkPlugin({ + name: ["vendor"], + }), + + // Define useful constants like TNS_WEBPACK + new webpack.DefinePlugin({ + "global.TNS_WEBPACK": "true", + }), + + // Copy assets to out dir. Add your own globs as needed. + new CopyWebpackPlugin([ + { from: mainSheet }, + { from: "css/**" }, + { from: "fonts/**" }, + { from: "**/*.jpg" }, + { from: "**/*.png" }, + { from: "**/*.xml" }, + ], { ignore: ["App_Resources/**"] }), + + // Generate a bundle starter script and activate it in package.json + new nsWebpack.GenerateBundleStarterPlugin([ + "./vendor", + "./bundle", + ]), + ]; + + if (env.uglify) { + plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true })); + + // Work around an Android issue by setting compress = false + const compress = platform !== "android"; + plugins.push(new webpack.optimize.UglifyJsPlugin({ + mangle: { except: nsWebpack.uglifyMangleExcludes }, + compress, + })); + } + + return plugins; +} + +// Resolve platform-specific modules like module.android.js +function getExtensions(platform) { + return Object.freeze([ + `.${platform}.ts`, + `.${platform}.js`, + `.${platform}.css`, + ".ts", + ".js", + ".css", + ]); +} diff --git a/templates/webpack.common.js.typescript.template b/templates/webpack.common.js.typescript.template deleted file mode 100644 index 464bb493..00000000 --- a/templates/webpack.common.js.typescript.template +++ /dev/null @@ -1,137 +0,0 @@ -var webpack = require("webpack"); -var nsWebpack = require("nativescript-dev-webpack"); -var nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); -var path = require("path"); -var CopyWebpackPlugin = require("copy-webpack-plugin"); -var ExtractTextPlugin = require("extract-text-webpack-plugin"); - -module.exports = function (platform, destinationApp) { - if (!destinationApp) { - // Default destination inside platforms//... - destinationApp = nsWebpack.getAppPath(platform); - } - var entry = {}; - // Discover entry module from package.json - entry.bundle = "./" + nsWebpack.getEntryModule(); - // Vendor entry with third party libraries. - entry.vendor = "./vendor"; - // app.css bundle - entry["app.css"] = "./app.css"; - - var plugins = [ - new ExtractTextPlugin("app.css"), - new webpack.optimize.CommonsChunkPlugin({ - name: ["vendor"] - }), - // Define useful constants like TNS_WEBPACK - new webpack.DefinePlugin({ - "global.TNS_WEBPACK": "true", - }), - // Copy assets to out dir. Add your own globs as needed. - new CopyWebpackPlugin([ - { from: "app.css" }, - { from: "css/**" }, - { from: "fonts/**" }, - { from: "**/*.jpg" }, - { from: "**/*.png" }, - { from: "**/*.xml" }, - ], { ignore: ["App_Resources/**"] }), - // Generate a bundle starter script and activate it in package.json - new nsWebpack.GenerateBundleStarterPlugin([ - "./vendor", - "./bundle", - ]), - ]; - - if (process.env.npm_config_uglify) { - plugins.push(new webpack.LoaderOptionsPlugin({ - minimize: true - })); - - // Work around an Android issue by setting compress = false - var compress = platform !== "android"; - plugins.push(new webpack.optimize.UglifyJsPlugin({ - mangle: { - except: nsWebpack.uglifyMangleExcludes, - }, - compress: compress, - })); - } - - return { - context: path.resolve("./app"), - target: nativescriptTarget, - entry: entry, - output: { - pathinfo: true, - path: path.resolve(destinationApp), - libraryTarget: "commonjs2", - filename: "[name].js", - }, - resolve: { - // Resolve platform-specific modules like module.android.js - extensions: [ - "." + platform + ".ts", - "." + platform + ".js", - "." + platform + ".css", - ".ts", - ".js", - ".css", - ], - // Resolve {N} system modules from tns-core-modules - modules: [ - "node_modules/tns-core-modules", - "node_modules", - ] - }, - node: { - // Disable node shims that conflict with NativeScript - "http": false, - "timers": false, - "setImmediate": false, - "fs": "empty", - }, - module: { - loaders: [ - { - test: /\.html$/, - loader: "raw-loader" - }, - // Root app.css file gets extracted with bundled dependencies - { - test: /app\.css$/, - loader: ExtractTextPlugin.extract([ - "resolve-url-loader", - "nativescript-css-loader", - "nativescript-dev-webpack/platform-css-loader", - ]), - }, - // Other CSS files get bundled using the raw loader - { - test: /\.css$/, - exclude: /app\.css$/, - loaders: [ - "raw-loader", - ] - }, - // Compile TypeScript files, replace templateUrl and styleUrls. - { - test: /\.ts$/, - loaders: [ - "awesome-typescript-loader", - ] - }, - // SASS support - { - test: /\.scss$/, - loaders: [ - "raw-loader", - "resolve-url-loader", - "sass-loader", - ] - }, - ] - }, - plugins: plugins, - }; -}; diff --git a/templates/webpack.ios.js.template b/templates/webpack.ios.js.template deleted file mode 100644 index 806f3ef2..00000000 --- a/templates/webpack.ios.js.template +++ /dev/null @@ -1,2 +0,0 @@ -var makeConfig = require("./webpack.common"); -module.exports = makeConfig("ios"); From b52e33ebc7a0ed66e11ddf2e602684d3a00a0aa2 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Wed, 10 May 2017 12:52:50 +0300 Subject: [PATCH 3/5] fix(ns-bundle): pass platform and uglify as env properties --- bin/ns-bundle | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/ns-bundle b/bin/ns-bundle index e3e468f8..8c828825 100644 --- a/bin/ns-bundle +++ b/bin/ns-bundle @@ -67,7 +67,16 @@ function webpack(platform) { return new Promise(function (resolve, reject) { console.log(`Running webpack for ${platform}...`); - spawnChildProcess(true, "webpack", `--config=webpack.${platform}.js`, "--progress") + const args = [ + true, // show output on console + `webpack`, + `--config=webpack.common.js`, + `--progress`, + `--env.${platform}`, + process.env.npm_config_uglify && `--env.uglify`, + ]; + + spawnChildProcess(...args) .then(resolve) .catch(throwError); }); From c75f255d36caaf2eaa84bab7bc07fd03b24b4097 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Wed, 10 May 2017 16:00:09 +0300 Subject: [PATCH 4/5] fix(ns-bundle): don't readd scripts from nativescript-dev-webpack --- npmScriptsManager.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/npmScriptsManager.js b/npmScriptsManager.js index 7ed09a15..1a60b469 100644 --- a/npmScriptsManager.js +++ b/npmScriptsManager.js @@ -17,6 +17,8 @@ const DEPRECATED_SCRIPT_TEMPLATES = Object.freeze([ const PLATFORMS = Object.freeze(["android", "ios"]); function addNpmScripts(scripts) { + scripts = scripts || {}; + Object.keys(SCRIPT_TEMPLATES).forEach(name => { packageJson = addPlatformScript(scripts, name, SCRIPT_TEMPLATES[name]); }); @@ -51,8 +53,8 @@ function addPlatformScript(scripts, nameTemplate, commandTemplate) { } function removePlatformScripts(scripts, nameTemplate) { - if (!scripts) { - return; + if (!scripts || Object.keys(SCRIPT_TEMPLATES).includes(nameTemplate)) { + return scripts; } PLATFORMS.forEach(function (platform) { From cd7efe85a87e27b3fcc7dcd2081176ffc8641448 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Wed, 10 May 2017 16:00:47 +0300 Subject: [PATCH 5/5] fix(ns-bundle): use webpack.config.js instead of webpack.common.js BREAKING: The ns-bundle script will now target the `webpack.config.js` file in your repository instead of the `webpack.common.js` one. If you changed your configuration, you need to apply them to `webpack.config.js` or replace the whole file with your correct configuration. The following files are no longer needed and can be safely removed from the project: `webpack.common.js`, `webpack.android.js`, `webpack.ios.js`. --- bin/ns-bundle | 11 +++++------ projectFilesManager.js | 6 +++--- templates/buildTemplates.js | 2 +- templates/common/imports.js | 3 +-- templates/ts/rules.js | 4 ++-- ...n.js.js.template => webpack.config.js.js.template} | 1 - ...n.js.ng.template => webpack.config.js.ng.template} | 1 - ...n.js.ts.template => webpack.config.js.ts.template} | 11 +++++++++-- 8 files changed, 21 insertions(+), 18 deletions(-) rename templates/{webpack.common.js.js.template => webpack.config.js.js.template} (99%) rename templates/{webpack.common.js.ng.template => webpack.config.js.ng.template} (99%) rename templates/{webpack.common.js.ts.template => webpack.config.js.ts.template} (95%) diff --git a/bin/ns-bundle b/bin/ns-bundle index 8c828825..b4baef3c 100644 --- a/bin/ns-bundle +++ b/bin/ns-bundle @@ -1,11 +1,10 @@ #!/usr/bin/env node -const spawn = require("child_process").spawn; -const resolve = require("path").resolve; +const { spawn } = require("child_process"); +const { resolve: pathResolve } = require("path"); +const { getPackageJson } = require("../projectHelpers"); -const getPackageJson = require("../projectHelpers").getPackageJson; - -const PROJECT_DIR = resolve(__dirname, "../../../"); +const PROJECT_DIR = pathResolve(__dirname, "../../../"); const packageJson = getPackageJson(PROJECT_DIR); if (!process.env.npm_config_argv) { @@ -70,7 +69,7 @@ function webpack(platform) { const args = [ true, // show output on console `webpack`, - `--config=webpack.common.js`, + `--config=webpack.config.js`, `--progress`, `--env.${platform}`, process.env.npm_config_uglify && `--env.uglify`, diff --git a/projectFilesManager.js b/projectFilesManager.js index 4b6a093a..0fb43ee0 100644 --- a/projectFilesManager.js +++ b/projectFilesManager.js @@ -53,12 +53,12 @@ function getProjectTemplates(projectDir) { let templates = {} if (helpers.isAngular({projectDir})) { - templates["webpack.common.js.ng.template"] = "webpack.common.js"; + templates["webpack.config.js.ng.template"] = "webpack.config.js"; templates["tsconfig.aot.json.template"] = "tsconfig.aot.json"; } else if (helpers.isTypeScript({projectDir})) { - templates["webpack.common.js.ts.template"] = "webpack.common.js"; + templates["webpack.config.js.ts.template"] = "webpack.config.js"; } else { - templates["webpack.common.js.js.template"] = "webpack.common.js"; + templates["webpack.config.js.js.template"] = "webpack.config.js"; } return getFullTemplatesPath(projectDir, templates); diff --git a/templates/buildTemplates.js b/templates/buildTemplates.js index 0ed0829a..1480e3ba 100644 --- a/templates/buildTemplates.js +++ b/templates/buildTemplates.js @@ -6,7 +6,7 @@ saveTemplate("ng"); function saveTemplate(target) { const content = buildTemplate(target); - writeFileSync(`./templates/webpack.common.js.${target}.template`, content); + writeFileSync(`./templates/webpack.config.js.${target}.template`, content); } function buildTemplate(target) { diff --git a/templates/common/imports.js b/templates/common/imports.js index fdc54d90..42217491 100644 --- a/templates/common/imports.js +++ b/templates/common/imports.js @@ -1,5 +1,4 @@ -module.exports = ` -const { resolve, join } = require("path"); +module.exports = `const { resolve, join } = require("path"); const webpack = require("webpack"); const nsWebpack = require("nativescript-dev-webpack"); diff --git a/templates/ts/rules.js b/templates/ts/rules.js index 5ea507c9..40d261c9 100644 --- a/templates/ts/rules.js +++ b/templates/ts/rules.js @@ -1,4 +1,4 @@ -module.exports = [ +module.exports = ` // Compile TypeScript files, replace templateUrl and styleUrls. { test: /\\.ts$/, @@ -6,4 +6,4 @@ module.exports = [ "awesome-typescript-loader", ] } -]; +`; diff --git a/templates/webpack.common.js.js.template b/templates/webpack.config.js.js.template similarity index 99% rename from templates/webpack.common.js.js.template rename to templates/webpack.config.js.js.template index bb35c0fe..dba466e5 100644 --- a/templates/webpack.common.js.js.template +++ b/templates/webpack.config.js.js.template @@ -1,4 +1,3 @@ - const { resolve, join } = require("path"); const webpack = require("webpack"); diff --git a/templates/webpack.common.js.ng.template b/templates/webpack.config.js.ng.template similarity index 99% rename from templates/webpack.common.js.ng.template rename to templates/webpack.config.js.ng.template index af57d05b..10af4b10 100644 --- a/templates/webpack.common.js.ng.template +++ b/templates/webpack.config.js.ng.template @@ -1,4 +1,3 @@ - const { resolve, join } = require("path"); const webpack = require("webpack"); diff --git a/templates/webpack.common.js.ts.template b/templates/webpack.config.js.ts.template similarity index 95% rename from templates/webpack.common.js.ts.template rename to templates/webpack.config.js.ts.template index 6d0ae6e2..a2284bc9 100644 --- a/templates/webpack.common.js.ts.template +++ b/templates/webpack.config.js.ts.template @@ -1,4 +1,3 @@ - const { resolve, join } = require("path"); const webpack = require("webpack"); @@ -107,7 +106,15 @@ function getRules() { ] }, -[object Object] + + // Compile TypeScript files, replace templateUrl and styleUrls. + { + test: /\.ts$/, + loaders: [ + "awesome-typescript-loader", + ] + } + ]; }