Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to with HtmlWebpackPlugin? #90

Open
rkmax opened this issue Apr 21, 2017 · 3 comments
Open

How to with HtmlWebpackPlugin? #90

rkmax opened this issue Apr 21, 2017 · 3 comments

Comments

@rkmax
Copy link

rkmax commented Apr 21, 2017

my config is the following

const { join } = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  context: __dirname,
  entry  : {
    main: './src/app.js'
  },
  output : {
    path         : join(__dirname, 'dist'),
    filename     : '[name].bundle.js',
    chunkFilename: '[id]_chunk.js'
  },
  module : {
    rules: [
      { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
      { test: /\.css$/, loader: "style-loader!css-loader" },
      { test: /\.(scss|sass)$/, loaders: ['style-loader', 'css-loader', 'sass-loader'] },
      { test: /\.(png|jpg|jpeg|gif)$/, loader: 'url-loader?limit=8192' },
    ]
  },
  plugins: [
    new webpack.ProvidePlugin({m: 'mithril'}),
    new HtmlWebpackPlugin({
      title: 'MyTitle'
    })
  ],
  devServer: {
    historyApiFallback: true
  }
};

my entry point is just rendering a simple component

import m from 'mithril';
import Landing from './landing';

import './styles/theme.scss';

m.render(document.body, m(Landing));

now when Add the static site generator at the end of plugin list always got an "Error: window is not defined" maybe I'm doing something wrong with my config

@rkmax rkmax changed the title How to with with HtmlWebpackPlugin? How to with HtmlWebpackPlugin? Apr 21, 2017
@nealgriffin
Copy link

I'm not sure if this'll help, but I ran into a similar issue and it was simply because I was not specifying the entry point correctly in webpack.config.js - the first argument to the plugin should be the name of your entry point, e.g. your entry point from above is:
entry : { main: './src/app.js' },
therefore in your webpack config you'd want to specify:
new StaticSiteGeneratorPlugin('main', some_array_of_routes, some_other_file),
specifying 'main' is what I had overlooked, hope it helps.

@rkmax
Copy link
Author

rkmax commented Apr 24, 2017

Still have the same error

@nealgriffin
Copy link

Understood. I was really interested in this, it took awhile to get the elements correct, but I did end up creating a repository that shows how to use this plugin with Mithril. I believe the root cause of the issues you are having is that mithril is expecting to be run from the browser and this plugin runs it from node's context. I walkthrough the steps I took to get the two to work together in the linked repository.

I'm not sure if it'll solve what you are ultimately trying to do, but my hope is that it is helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants