mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
chore(e2e): clean up webpack files (#5807)
* chore(e2e): clean up webpack files * chore(gitignore): clean up and add webpack files * chore(gitignore): clean up webpack files * chore(deps): clean up devDependencies
This commit is contained in:
76
.gitignore
vendored
76
.gitignore
vendored
@ -1,4 +1,41 @@
|
||||
# generated files
|
||||
# Folders
|
||||
dist
|
||||
hooks
|
||||
libs
|
||||
node_modules
|
||||
package
|
||||
platforms
|
||||
reports
|
||||
tags
|
||||
|
||||
# Files
|
||||
package-lock.json
|
||||
.DS_Store
|
||||
.nsbuildinfo
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# Appium files
|
||||
e2e/**/*.trace/
|
||||
e2e/**/test-results.xml
|
||||
|
||||
# Webpack configuration files
|
||||
webpack.config.js
|
||||
|
||||
# Generated files
|
||||
*.map
|
||||
*.tgz
|
||||
.baseDir.ts
|
||||
@ -6,10 +43,7 @@
|
||||
tscommand*.tmp.txt
|
||||
.tscache
|
||||
|
||||
node_modules/
|
||||
dist/
|
||||
package/
|
||||
|
||||
# Other
|
||||
*.js
|
||||
!tests/hooks/**/*.*
|
||||
!gruntfile.js
|
||||
@ -19,44 +53,14 @@ package/
|
||||
!fetch/**/*.*
|
||||
!apps/TelerikNEXT/lib/**/*.*
|
||||
!build/**/*.*
|
||||
CrossPlatformModules.sln.ide/
|
||||
*.suo
|
||||
CrossPlatformModules.suo
|
||||
CrossPlatformModules.v14.suo
|
||||
CrossPlatformModules.csproj.user
|
||||
bin/
|
||||
obj/
|
||||
.vs/
|
||||
.idea/
|
||||
|
||||
.baseDir.ts
|
||||
.ctags-exclude
|
||||
tags
|
||||
|
||||
TestRunResult.txt
|
||||
.testsapprun
|
||||
|
||||
tns-core-modules.base.d.ts
|
||||
tns-core-modules.d.ts
|
||||
tns-core-modules.es6.d.ts
|
||||
|
||||
tests/platforms/
|
||||
tests/lib/
|
||||
*.log
|
||||
|
||||
.DS_Store
|
||||
|
||||
apps/platforms/
|
||||
apps/lib/
|
||||
apps/hooks/
|
||||
apps/node_modules/
|
||||
|
||||
e2e/**/platforms
|
||||
!e2e/**/webpack.config.js
|
||||
e2e/**/reports/
|
||||
e2e/**/*.trace/
|
||||
e2e/**/test-results.xml
|
||||
|
||||
package-lock.json
|
||||
|
||||
.nsbuildinfo
|
||||
tns-core-modules.es6.d.ts
|
@ -1,9 +0,0 @@
|
||||
require("application");
|
||||
if (!global["__snapshot"]) {
|
||||
// In case snapshot generation is enabled these modules will get into the bundle
|
||||
// but will not be required/evaluated.
|
||||
// The snapshot webpack plugin will add them to the tns-java-classes.js bundle file.
|
||||
// This way, they will be evaluated on app start as early as possible.
|
||||
require("ui/frame");
|
||||
require("ui/frame/activity");
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
// There is a bug in angular: https://github.com/angular/angular-cli/pull/8589/files
|
||||
// Legendary stuff, its webpack plugin pretty much doesn't work with empty TypeScript files in v1.8.3
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
void 0;
|
@ -1,10 +0,0 @@
|
||||
// Snapshot the ~/app.css and the theme
|
||||
const application = require("application");
|
||||
require("ui/styling/style-scope");
|
||||
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/);
|
||||
global.registerWebpackModules(appCssContext);
|
||||
application.loadAppCss();
|
||||
|
||||
require("./vendor-platform");
|
||||
|
||||
require("bundle-entry-points");
|
@ -17,29 +17,9 @@
|
||||
"tns-core-modules": "next"
|
||||
},
|
||||
"devDependencies": {
|
||||
"awesome-typescript-loader": "~3.1.3",
|
||||
"babel-traverse": "6.26.0",
|
||||
"babel-types": "6.26.0",
|
||||
"babylon": "6.18.0",
|
||||
"copy-webpack-plugin": "~4.3.0",
|
||||
"css-loader": "~0.28.7",
|
||||
"extract-text-webpack-plugin": "~3.0.2",
|
||||
"lazy": "1.0.11",
|
||||
"nativescript-dev-appium": "next",
|
||||
"nativescript-dev-typescript": "next",
|
||||
"nativescript-dev-webpack": "next",
|
||||
"nativescript-worker-loader": "~0.8.1",
|
||||
"raw-loader": "~0.5.1",
|
||||
"resolve-url-loader": "~2.2.1",
|
||||
"typescript": "~2.4.2",
|
||||
"uglifyjs-webpack-plugin": "~1.1.6",
|
||||
"webpack": "~3.10.0",
|
||||
"webpack-bundle-analyzer": "^2.9.1",
|
||||
"webpack-sources": "~1.1.0",
|
||||
"@types/chai": "^4.0.2",
|
||||
"@types/mocha": "^2.2.41",
|
||||
"@types/node": "^7.0.5",
|
||||
"clean-webpack-plugin": "~0.1.19"
|
||||
"nativescript-dev-webpack": "next"
|
||||
},
|
||||
"scripts": {
|
||||
"e2e": "tsc -p e2e && mocha --opts ./e2e/config/mocha.opts",
|
||||
|
@ -1,179 +0,0 @@
|
||||
const { relative, resolve, join } = require("path");
|
||||
|
||||
const webpack = require("webpack");
|
||||
const nsWebpack = require("nativescript-dev-webpack");
|
||||
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
|
||||
const CleanWebpackPlugin = require("clean-webpack-plugin");
|
||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
|
||||
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
|
||||
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
|
||||
|
||||
module.exports = env => {
|
||||
const platform = env && (env.android && "android" || env.ios && "ios");
|
||||
if (!platform) {
|
||||
throw new Error("You need to provide a target platform!");
|
||||
}
|
||||
|
||||
const platforms = ["ios", "android"];
|
||||
const projectRoot = __dirname;
|
||||
// Default destination inside platforms/<platform>/...
|
||||
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform));
|
||||
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";
|
||||
|
||||
const {
|
||||
// The 'appPath' and 'appResourcesPath' values are fetched from
|
||||
// the nsconfig.json configuration file
|
||||
// when bundling with `tns run android|ios --bundle`.
|
||||
appPath = "app",
|
||||
appResourcesPath = "app/App_Resources",
|
||||
|
||||
// Snapshot, uglify and report can be enabled by providing
|
||||
// the `--env.snapshot`, `--env.uglify` or `--env.report` flags
|
||||
// when running 'tns run android|ios'
|
||||
snapshot,
|
||||
uglify,
|
||||
report,
|
||||
} = env;
|
||||
|
||||
const appFullPath = resolve(projectRoot, appPath);
|
||||
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
|
||||
|
||||
const config = {
|
||||
context: appFullPath,
|
||||
watchOptions: {
|
||||
ignored: [
|
||||
appResourcesFullPath,
|
||||
// Don't watch hidden files
|
||||
"**/.*",
|
||||
]
|
||||
},
|
||||
target: nativescriptTarget,
|
||||
entry: {
|
||||
bundle: `./${nsWebpack.getEntryModule(appFullPath)}`,
|
||||
vendor: "./vendor"
|
||||
},
|
||||
output: {
|
||||
pathinfo: true,
|
||||
path: dist,
|
||||
libraryTarget: "commonjs2",
|
||||
filename: "[name].js",
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".ts", ".js", ".scss", ".css"],
|
||||
// Resolve {N} system modules from tns-core-modules
|
||||
modules: [
|
||||
"node_modules/tns-core-modules",
|
||||
"node_modules",
|
||||
],
|
||||
alias: {
|
||||
'~': resolve("./app")
|
||||
},
|
||||
// don't resolve symlinks to symlinked modules
|
||||
symlinks: false
|
||||
},
|
||||
resolveLoader: {
|
||||
// don't resolve symlinks to symlinked loaders
|
||||
symlinks: false
|
||||
},
|
||||
node: {
|
||||
// Disable node shims that conflict with NativeScript
|
||||
"http": false,
|
||||
"timers": false,
|
||||
"setImmediate": false,
|
||||
"fs": "empty",
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{ test: /\.(html|xml)$/, use: "raw-loader" },
|
||||
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: { loader: "css-loader", options: { minimize: false, url: false } }
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
{ loader: "css-loader", options: { minimize: false, url: false } },
|
||||
"sass-loader"
|
||||
]
|
||||
},
|
||||
|
||||
{ test: /\.ts$/, use: "awesome-typescript-loader" }
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
// 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",
|
||||
}),
|
||||
// Remove all files from the out dir.
|
||||
new CleanWebpackPlugin([ `${dist}/**/*` ]),
|
||||
// Copy native app resources to out dir.
|
||||
new CopyWebpackPlugin([
|
||||
{
|
||||
from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,
|
||||
to: `${dist}/App_Resources/${appResourcesPlatformDir}`,
|
||||
context: projectRoot
|
||||
},
|
||||
]),
|
||||
// Copy assets to out dir. Add your own globs as needed.
|
||||
new CopyWebpackPlugin([
|
||||
{ from: "fonts/**" },
|
||||
{ from: "**/*.jpg" },
|
||||
{ from: "**/*.png" },
|
||||
{ from: "**/*.xml" },
|
||||
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
|
||||
// Generate a bundle starter script and activate it in package.json
|
||||
new nsWebpack.GenerateBundleStarterPlugin([
|
||||
"./vendor",
|
||||
"./bundle",
|
||||
]),
|
||||
// Support for web workers since v3.2
|
||||
new NativeScriptWorkerPlugin(),
|
||||
new nsWebpack.PlatformFSPlugin({
|
||||
platform,
|
||||
platforms,
|
||||
}),
|
||||
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
|
||||
new nsWebpack.WatchStateLoggerPlugin(),
|
||||
],
|
||||
};
|
||||
if (report) {
|
||||
// Generate report files for bundles content
|
||||
config.plugins.push(new BundleAnalyzerPlugin({
|
||||
analyzerMode: "static",
|
||||
openAnalyzer: false,
|
||||
generateStatsFile: true,
|
||||
reportFilename: resolve(projectRoot, "report", `report.html`),
|
||||
statsFilename: resolve(projectRoot, "report", `stats.json`),
|
||||
}));
|
||||
}
|
||||
if (snapshot) {
|
||||
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
|
||||
chunk: "vendor",
|
||||
projectRoot,
|
||||
webpackConfig: config,
|
||||
targetArchs: ["arm", "arm64", "ia32"],
|
||||
tnsJavaClassesOptions: { packages: ["tns-core-modules" ] },
|
||||
useLibs: false
|
||||
}));
|
||||
}
|
||||
if (uglify) {
|
||||
config.plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true }));
|
||||
|
||||
// Work around an Android issue by setting compress = false
|
||||
const compress = platform !== "android";
|
||||
config.plugins.push(new UglifyJsPlugin({
|
||||
uglifyOptions: {
|
||||
compress,
|
||||
}
|
||||
}));
|
||||
}
|
||||
return config;
|
||||
};
|
Reference in New Issue
Block a user