Skip to content

Commit 35c5b4d

Browse files
authored
refactor: add runtime-vue (#73)
* chore: add runtime-vue * chore: add example * chore: add missing dependencies
1 parent af79a4d commit 35c5b4d

31 files changed

+427
-220
lines changed

examples/vue/package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "vue",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "",
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC"
13+
}

examples/vue/pages.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
router: {
3+
mode: 'history',
4+
}
5+
}

examples/vue/src/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default () => {}

examples/vue/src/pages/hello.vue

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div>
3+
Hello
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
}
10+
</script>
11+
12+
<style lang="css">
13+
</style>

examples/vue/src/pages/home.vue

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div>
3+
Home
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
}
10+
</script>
11+
12+
<style lang="css">
13+
</style>

packages/driver-pages/lib/driver.js

+23-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const exit = require( 'exit' )
99
const whyIsNodeRunning = require( 'why-is-node-running' )
1010
const VirtualModulesPlugin = require( '@nut-project/webpack-virtual-modules' )
1111
const HtmlWebpackPlugin = require( 'html-webpack-plugin' )
12+
const CopyPlugin = require( 'copy-webpack-plugin' )
1213
const BundleAnalyzerPlugin = require( 'webpack-bundle-analyzer' ).BundleAnalyzerPlugin
1314
const WebpackBar = require( 'webpackbar' )
1415
const {
@@ -21,6 +22,7 @@ const {
2122
SyncHook, SyncWaterfallHook, AsyncSeriesHook, AsyncSeriesWaterfallHook
2223
} = require( 'tapable' )
2324
const getPages = require( './get-pages' )
25+
const extendWebpack = require( './webpack' )
2426

2527
class PagesDriver {
2628
constructor( options ) {
@@ -228,8 +230,12 @@ class PagesDriver {
228230
}
229231

230232
_setupWebpack() {
233+
const config = this.config
234+
231235
this._webpack = chain()
232236

237+
extendWebpack( this )
238+
233239
// virtual modules
234240
const virtualModules = this._virtualModules = new VirtualModulesPlugin(
235241
this._getDefaultModules()
@@ -267,9 +273,20 @@ class PagesDriver {
267273
.add( path.join( root, '../../' ) )
268274
.add( path.join( root, 'node_modules' ) )
269275

276+
this.webpack
277+
.plugin( 'copy' )
278+
.use( CopyPlugin, [] )
279+
270280
this.webpack
271281
.plugin( 'html' )
272-
.use( HtmlWebpackPlugin )
282+
.use( HtmlWebpackPlugin, [
283+
{
284+
template: path.join( __dirname, './webpack/template.ejs' ),
285+
title: config.html && config.html.title,
286+
favicon: config.html && config.html.favicon,
287+
excludeChunks: [],
288+
}
289+
] )
273290

274291
this.webpack
275292
.plugin( 'webpackbar' )
@@ -284,11 +301,11 @@ class PagesDriver {
284301
async apply() {
285302
const { cli } = this
286303

287-
// make webpack available
288-
this._setupWebpack()
289-
290304
await this.getConfig()
291305

306+
// make this.webpack available
307+
this._setupWebpack()
308+
292309
if ( await this.getConfigFile() ) {
293310
this.verbose = this.config.verbose === true
294311
} else {
@@ -560,11 +577,11 @@ class PagesDriver {
560577
}
561578

562579
get cliOptions() {
563-
return this._cliOptions
580+
return this._cliOptions || {}
564581
}
565582

566583
get config() {
567-
return this._config
584+
return this._config || {}
568585
}
569586

570587
get webpack() {

plugins/pages/microfrontends/lib/webpack/config/base.js renamed to packages/driver-pages/lib/webpack/base.js

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const resolveFrom = require( 'resolve-from' )
1313
env = 'development',
1414
clean = true,
1515
browserslist: [],
16-
transpileModules: [],
1716
include,
1817
exclude,
1918
}
+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
const path = require( 'path' )
2+
const base = require( './base' )
3+
const dev = require( './dev' )
4+
const prod = require( './prod' )
5+
6+
const DEFAULTS = {
7+
browserslist: [ '>1%', 'last 4 versions', 'Firefox ESR', 'not ie < 9' ]
8+
}
9+
10+
function tryRequirePackage( context ) {
11+
let pkg
12+
13+
try {
14+
pkg = require( path.join( context, 'package.json' ) )
15+
} catch ( e ) {}
16+
17+
return pkg
18+
}
19+
20+
const ID = 'driver-pages:webpack'
21+
22+
module.exports = function ( api ) {
23+
api.hooks.chainWebpack.tapPromise( ID, async () => {
24+
const pkg = tryRequirePackage( process.cwd() )
25+
26+
const browserslist = api.config.browserslist ||
27+
( pkg && pkg.browserslist ) ||
28+
DEFAULTS.browserslist
29+
30+
let transpileModules = (
31+
api.config.babel && api.config.babel.transpileModules
32+
) || []
33+
34+
// clone
35+
transpileModules = transpileModules.slice()
36+
37+
if ( api.config && api.config.plugins ) {
38+
api.config.plugins.forEach( plugin => {
39+
const pkg = tryRequirePackage( plugin.context )
40+
41+
if ( pkg ) {
42+
transpileModules.push( pkg.name )
43+
} else {
44+
transpileModules.push( function ( filepath ) {
45+
return filepath.includes( plugin.context )
46+
} )
47+
}
48+
} )
49+
}
50+
51+
const exclude = [
52+
/\.nut\/pages\.js/,
53+
/\.nut\/routes\.js/,
54+
/\.nut\/route-components\//,
55+
]
56+
57+
const includeCaches = {}
58+
59+
// from egoist/poi
60+
function include( filepath ) {
61+
filepath = filepath.replace( /\\/g, '/' )
62+
63+
// use cache
64+
if ( typeof includeCaches[ filepath ] === 'boolean' ) {
65+
return includeCaches[ filepath ]
66+
}
67+
68+
if ( !filepath.includes( 'node_modules' ) ) {
69+
includeCaches[ filepath ] = true
70+
return true
71+
}
72+
73+
if ( transpileModules ) {
74+
const shouldTranspile = transpileModules.some( m => {
75+
if ( typeof m === 'string' ) {
76+
return filepath.includes( `/node_modules/${ m }/` ) ||
77+
filepath.includes( `/node_modules/_${ m.replace( /\//g, '_' ) }` )
78+
}
79+
80+
if ( typeof m === 'function' ) {
81+
return m( filepath )
82+
}
83+
84+
if ( m && m.test ) {
85+
return m.test( filepath )
86+
}
87+
88+
return false
89+
} )
90+
91+
includeCaches[ filepath ] = shouldTranspile
92+
return shouldTranspile
93+
}
94+
95+
includeCaches[ filepath ] = false
96+
return false
97+
}
98+
99+
const options = {
100+
browserslist,
101+
include,
102+
exclude,
103+
clean: api.config.output && api.config.output.clean === true,
104+
publicPath: api.config.output && api.config.output.publicPath,
105+
}
106+
107+
base( api.webpack, options )
108+
109+
if ( api.env === 'production' ) {
110+
prod( api.webpack, options )
111+
} else {
112+
dev( api.webpack, options )
113+
}
114+
} )
115+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title><%= htmlWebpackPlugin.options.title %></title>
5+
</head>
6+
<body>
7+
<noscript>
8+
We're sorry but our website doesn't work properly without JavaScript enabled. Please enable it to continue.
9+
</noscript>
10+
</body>
11+
</html>

packages/driver-pages/package.json

+65-24
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,101 @@
11
{
22
"name": "@nut-project/driver-pages",
33
"version": "1.0.0-alpha.3",
4-
"publishConfig": {
5-
"access": "public"
6-
},
74
"description": "A framework born for micro frontends",
85
"keywords": [
9-
"microfrontends",
10-
"micro",
11-
"frontend",
126
"architecture",
13-
"spa",
147
"cli",
15-
"static site generator",
16-
"hmr"
17-
],
18-
"main": "lib/index.js",
19-
"files": [
20-
"bin",
21-
"lib",
22-
"yarn.lock",
23-
"README.md"
8+
"frontend",
9+
"hmr",
10+
"micro",
11+
"microfrontends",
12+
"spa",
13+
"static site generator"
2414
],
25-
"engines": {
26-
"node": ">=8.9.0"
27-
},
28-
"repository": "https://github.com/nut-project/nut/tree/master/packages/gatherer",
2915
"homepage": "http://nut.js.org",
3016
"bugs": {
3117
"url": "https://github.com/nut-project/nut/issues/new/choose"
3218
},
33-
"scripts": {
34-
"prepublishOnly": "cp ../../README.md ./README.md"
35-
},
19+
"repository": "https://github.com/nut-project/nut/tree/master/packages/gatherer",
20+
"license": "MIT",
3621
"author": {
3722
"name": "fengzilong",
3823
"email": "fengzilong1992@gmail.com",
3924
"url": "https://github.com/fengzilong"
4025
},
41-
"license": "MIT",
26+
"files": [
27+
"bin",
28+
"lib",
29+
"yarn.lock",
30+
"README.md"
31+
],
32+
"main": "lib/index.js",
33+
"scripts": {
34+
"prepublishOnly": "cp ../../README.md ./README.md"
35+
},
4236
"dependencies": {
37+
"@babel/core": "^7.6.2",
38+
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
39+
"@babel/plugin-transform-runtime": "^7.6.2",
40+
"@babel/preset-env": "^7.6.2",
41+
"@babel/preset-react": "^7.0.0",
42+
"@babel/runtime": "^7.6.2",
4343
"@nut-project/dev-utils": "^1.0.0-alpha.2",
44+
"@nut-project/mini-css-extract": "^1.0.0-alpha.2",
4445
"@nut-project/webpack": "^1.0.0-alpha.2",
4546
"@nut-project/webpack-virtual-modules": "^1.0.0-alpha.2",
47+
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
48+
"@vue/babel-preset-jsx": "^1.1.0",
49+
"autoprefixer": "^9.6.1",
50+
"babel-loader": "^8.0.6",
51+
"cache-loader": "^4.1.0",
52+
"case-sensitive-paths-webpack-plugin": "^2.2.0",
4653
"chokidar": "^3.1.0",
54+
"clean-webpack-plugin": "^3.0.0",
55+
"copy-webpack-plugin": "^5.0.4",
56+
"css-loader": "^3.2.0",
4757
"exit": "^0.1.2",
58+
"file-loader": "^4.2.0",
59+
"fork-ts-checker-webpack-plugin": "^1.5.0",
60+
"friendly-errors-webpack-plugin": "^1.7.0",
4861
"globby": "^10.0.1",
4962
"html-webpack-plugin": "^3.2.0",
5063
"import-fresh": "^3.1.0",
64+
"less": "^3.10.3",
65+
"less-loader": "^5.0.0",
66+
"optimize-css-assets-webpack-plugin": "^5.0.3",
67+
"postcss": "^7.0.21",
68+
"postcss-loader": "^3.0.0",
5169
"pretty-bytes": "^5.2.0",
70+
"pug": "^2.0.4",
71+
"pug-plain-loader": "^1.0.0",
72+
"raw-loader": "^3.1.0",
5273
"readline": "^1.3.0",
5374
"resolve-from": "^5.0.0",
75+
"sass": "^1.23.3",
76+
"sass-loader": "^8.0.0",
77+
"style-loader": "^1.0.0",
78+
"stylus": "^0.54.7",
79+
"stylus-loader": "^3.0.2",
5480
"tapable": "^1.1.3",
81+
"terser-webpack-plugin": "^2.1.0",
82+
"thread-loader": "^2.1.3",
5583
"tildify": "^2.0.0",
84+
"ts-loader": "^6.1.2",
85+
"tslint": "^5.18.0",
86+
"typescript": "^3.6.3",
87+
"url-loader": "^2.1.0",
88+
"vue": "^2.6.10",
89+
"vue-loader": "^15.7.2",
90+
"vue-template-compiler": "^2.6.10",
5691
"webpack-bundle-analyzer": "^3.6.0",
5792
"webpackbar": "^4.0.0",
5893
"why-is-node-running": "^2.1.0"
94+
},
95+
"engines": {
96+
"node": ">=8.9.0"
97+
},
98+
"publishConfig": {
99+
"access": "public"
59100
}
60101
}

packages/webpack-presets/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)