我安装了一个反应startUpapp并添加了Webpack,但它说 Can't resolve './src/index.js'
webpack.config.js文件看:
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
module.exports = {
context: path.join(__dirname, "public"),
devtool: debug ? "inline-sourcemap" : false,
entry: "./src/index.js",
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2016', 'stage-0'],
plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties'],
}
}
]
},
output: {
path: __dirname + "/public/",
filename: "build.js"
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(), …Run Code Online (Sandbox Code Playgroud) 我开始创建我的应用程序,所以我使用 webpack 实现了项目配置。项目结构为:
node_modules
public
|----bundle.js
|----index.html
src
|----app.jsx
|----index.jsx
|----components
|-----appBar.jsx
Run Code Online (Sandbox Code Playgroud)
webpack.config.jsx:
const path = require('path');
module.exports = {
mode: 'development',
entry: path.resolve(__dirname, 'src/index.jsx'),
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.jsx$/,
exclude: /node_modules/,
loader: 'babel-loader',
}
]
},
devServer: {
contentBase: path.join(__dirname, 'public'),
compress: true,
port: 9000
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序.jsx:
import ButtonAppBar from './components/appBar';
import React from 'react';
class App extends React.Component {
render(){
return (
<div>
<ButtonAppBar />
</div>
) …Run Code Online (Sandbox Code Playgroud) 我有一个在Node.js和浏览器中使用的内部库.它有许多文件,与Grunt任务和不同的序言连接,一个用于浏览器,一个用于Node:
浏览器:
// dependent 3rd-party libs like Mustache are already global
window.myLib = { /*just a namespace object filled with stuff later*/ }
// then comes the plain javascript which just adds elements to myLib.
// This part is identical to that used in Node
// example:
myLib.renderPartDetail = function (...) {...};
Run Code Online (Sandbox Code Playgroud)
节点:
var Mustache = require('mustache');
var myLib = {};
module.exports = myLib;
// then comes the plain javascript which just adds elements to myLib.
// This part is …Run Code Online (Sandbox Code Playgroud)