Skip to content

Commit 141162b

Browse files
committed
drop: notes
1 parent 6c7aa50 commit 141162b

File tree

1 file changed

+246
-0
lines changed

1 file changed

+246
-0
lines changed

changes.md

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
https://github.com/NativeScript/nativescript-app-templates/blob/master/shared/tools/dot.gitignore
2+
3+
`shared/tools/dot.gitignore` is missing various files from my `tools/dot.gitignore`, which used to be:
4+
5+
```
6+
# NativeScript
7+
hooks/
8+
node_modules/
9+
platforms/
10+
11+
# NativeScript Template
12+
*.js.map
13+
*.js
14+
15+
# React NativeScript
16+
!webpack.config.js
17+
18+
# Logs
19+
logs
20+
*.log
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
# General
26+
.DS_Store
27+
.AppleDouble
28+
.LSOverride
29+
.idea
30+
.cloud
31+
.project
32+
tmp/
33+
typings/
34+
35+
# Visual Studio Code
36+
.vscode/*
37+
!.vscode/settings.json
38+
!.vscode/tasks.json
39+
!.vscode/launch.json
40+
!.vscode/extensions.json
41+
```
42+
43+
https://github.com/NativeScript/nativescript-app-templates/blob/master/shared/hooks/after-createProject/after-createProject.js
44+
45+
My `hooks/after-createProject/after-createProject.js` hook used to look like this:
46+
47+
```js
48+
const fs = require("fs");
49+
const path = require("path");
50+
51+
/**
52+
* @see https://github.com/NativeScript/nativescript-app-templates/blob/master/packages/template-hello-world-ts/hooks/after-createProject/after-createProject.js
53+
*/
54+
module.exports = function (hookArgs) {
55+
const appRootFolder = hookArgs.projectDir;
56+
const toolsDir = path.join(appRootFolder, "tools");
57+
const vscodeDir = path.join(appRootFolder, ".vscode");
58+
const srcGitignore = path.join(toolsDir, "dot.gitignore");
59+
const destGitignore = path.join(appRootFolder, ".gitignore");
60+
// I'll continue to copy this file across, but omit the recommendation for "nativescript.nativescript" as that's Core-focused.
61+
const srcVscodeExtensions = path.join(toolsDir, "vscode.extensions.json");
62+
const destVscodeExtensions = path.join(vscodeDir, "extensions.json");
63+
64+
try {
65+
fs.mkdirSync(vscodeDir);
66+
fs.copyFileSync(srcVscodeExtensions, destVscodeExtensions);
67+
fs.copyFileSync(srcGitignore, destGitignore);
68+
} catch (error) {
69+
console.log(error);
70+
} finally {
71+
try {
72+
deleteFolderSync(toolsDir);
73+
74+
const readme = path.join(appRootFolder, "README.md");
75+
fs.unlinkSync(readme);
76+
77+
deleteFolderSync(__dirname);
78+
} catch (error) {
79+
console.log(error);
80+
}
81+
}
82+
83+
function deleteFolderSync(folderPath) {
84+
if (fs.statSync(folderPath).isDirectory()) {
85+
fs.readdirSync(folderPath).forEach((file) => {
86+
const content = path.join(folderPath, file);
87+
const contentDirs = fs.statSync(content).isDirectory();
88+
89+
if (contentDirs) {
90+
deleteFolderSync(content);
91+
} else {
92+
fs.unlinkSync(content);
93+
}
94+
});
95+
96+
fs.rmdirSync(folderPath);
97+
}
98+
}
99+
};
100+
```
101+
102+
103+
They've removed my `webpack.config.js`:
104+
105+
```js
106+
/**
107+
* @see https://github.com/NativeScript/NativeScript/tree/feat/ns7-finishing-touches/packages/webpack/templates
108+
* @see https://github.com/NativeScript/NativeScript/pull/8801/files
109+
*/
110+
const webpackConfig = require("./webpack.typescript");
111+
const webpack = require("webpack");
112+
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
113+
114+
module.exports = (env) => {
115+
env = env || {};
116+
const hmr = env.hmr;
117+
const production = env.production;
118+
const isAnySourceMapEnabled = !!env.sourceMap || !!env.hiddenSourceMap;
119+
120+
const baseConfig = webpackConfig(env);
121+
122+
/** Find the rule for transpiling ts files ("ts-loader"), and modify it to test for .tsx files too. */
123+
const tsxRule = baseConfig.module.rules.find(rule => rule.use && rule.use.loader === "ts-loader");
124+
tsxRule.test = /\.(ts|tsx)$/;
125+
tsxRule.use = [
126+
/**
127+
* Add React Refresh HMR support.
128+
* @see https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/55028c6355b31e697e21bf3e9a48613a7b94bee7/examples/typescript-without-babel/webpack.config.js#L18-L21
129+
*/
130+
hmr && !production && {
131+
loader: "babel-loader",
132+
options: {
133+
sourceMaps: isAnySourceMapEnabled ? "inline" : false,
134+
babelrc: false,
135+
plugins: ['react-refresh/babel']
136+
}
137+
},
138+
tsxRule.use,
139+
].filter(Boolean);
140+
141+
/**
142+
* Modify "nativescript-dev-webpack/hmr/hot-loader" to test for .tsx files
143+
* (and also js files, which it should have been doing to begin with!)
144+
*/
145+
const nativeScriptDevWebpackHotLoader = baseConfig.module.rules.find(rule =>
146+
rule.use === "@nativescript/webpack/hmr/hot-loader"
147+
);
148+
nativeScriptDevWebpackHotLoader.test = /\.(ts|tsx|js|css|scss|html|xml)$/;
149+
150+
/** We don't officially support JSX. Makes the webpack config rather more complicated to set up. */
151+
baseConfig.resolve.extensions = [".tsx", ...baseConfig.resolve.extensions];
152+
baseConfig.resolve.alias["react-dom"] = "react-nativescript";
153+
154+
/** Augment NativeScript's existing DefinePlugin definitions with a few more of our own. */
155+
const existingDefinePlugin = baseConfig.plugins.find(plugin =>
156+
plugin && plugin.constructor && plugin.constructor.name === "DefinePlugin"
157+
);
158+
baseConfig.plugins.splice(
159+
baseConfig.plugins.indexOf(existingDefinePlugin),
160+
1,
161+
new webpack.DefinePlugin({
162+
...existingDefinePlugin.definitions,
163+
/** For various libraries in the React ecosystem. */
164+
"__DEV__": production ? "false" : "true",
165+
"__TEST__": "false",
166+
/**
167+
* Primarily for React Fast Refresh plugin, but technically the allowHmrInProduction option could be used instead.
168+
* Worth including anyway, as there are plenty of Node libraries that use this flag.
169+
*/
170+
"process.env.NODE_ENV": JSON.stringify(production ? "production" : "development"),
171+
}),
172+
);
173+
174+
if(hmr && !production){
175+
baseConfig.plugins.push(new ReactRefreshWebpackPlugin({
176+
/**
177+
* Maybe one day we'll implement an Error Overlay, but the work involved is too daunting for now.
178+
* @see https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/79#issuecomment-644324557
179+
*/
180+
overlay: false,
181+
/**
182+
* If you (temporarily) want to enable HMR on a production build:
183+
* 1) Set `forceEnable` to `true`
184+
* 2) Remove the `!production` condition on `tsxRule` to ensure that babel-loader gets used.
185+
*/
186+
forceEnable: false,
187+
}));
188+
} else {
189+
baseConfig.plugins = baseConfig.plugins.filter(p => !(p && p.constructor && p.constructor.name === "HotModuleReplacementPlugin"));
190+
}
191+
192+
return baseConfig;
193+
};
194+
```
195+
196+
My `package.json` changed, in that:
197+
198+
* the main file is changed from `app.js` to `src/app.ts` (which may be right)
199+
* an explicit `files` array is now provided (which could well be wrong), whereas before I guess we relied on this `.npmignore` (which is still present)
200+
* Some deps updated (figuring out Webpack 5 is the main problem)
201+
202+
```
203+
"files": [
204+
"src",
205+
"App_Resources",
206+
"tools",
207+
"hooks",
208+
"!tools/assets",
209+
".editorconfig",
210+
"tsconfig.json",
211+
"patches"
212+
],
213+
```
214+
215+
```
216+
npm-debug.log
217+
.DS_Store
218+
219+
*.js.map
220+
*.js
221+
!webpack.config.js
222+
hooks/*
223+
!hooks/after-createProject/after-createProject.js
224+
lib/
225+
node_modules/
226+
platforms/
227+
tmp/
228+
typings/
229+
.idea
230+
.cloud
231+
.project
232+
.vscode
233+
.npmrc
234+
*.tgz
235+
```
236+
237+
```diff
238+
- "@nativescript/core": "~7.1.0",
239+
+ "@nativescript/core": "~8.0.0",
240+
241+
- "@nativescript/types": "^7.0.4",
242+
+ "@nativescript/types": "^8.0.0",
243+
244+
- "@nativescript/webpack": "~4.0.0",
245+
+ "@nativescript/webpack": "5.0.0-beta.0",
246+
```

0 commit comments

Comments
 (0)